local case = require("dial.augend").case

describe("Test of case between camelCase and snake_case (cyclic = true):", function()
    local augend = case.new { types = { "camelCase", "snake_case" }, cyclic = true }

    describe("find function", function()
        it("can find camelCase or snake_case identifier", function()
            assert.are.same(augend:find("fooBar", 1), { from = 1, to = 6 })
            assert.are.same(augend:find("fooBarBaz", 1), { from = 1, to = 9 })
            assert.are.same(augend:find("fooBarBazPiyo9", 1), { from = 1, to = 14 })
            assert.are.same(augend:find("foo_bar", 1), { from = 1, to = 7 })
        end)
        it("skips non-camelCase and non-snake_case word", function()
            assert.are.same(augend:find("foo_Bar_baz_foo", 1), nil)
            assert.are.same(augend:find("foo_Bar", 1), nil)
            assert.are.same(augend:find("FooBar", 1), nil)
            assert.are.same(augend:find("1foo_bar", 1), nil)
        end)
        it("skips identifier constructed from one word", function()
            assert.are.same(augend:find("foo", 1), nil)
            assert.are.same(augend:find("foo bar_baz", 1), { from = 5, to = 11 })
        end)
        it("chooses the one in front", function()
            assert.are.same(augend:find("foo_bar fooBar", 1), { from = 1, to = 7 })
            assert.are.same(augend:find("foo_bar fooBar", 8), { from = 9, to = 14 })
            assert.are.same(augend:find("fooBar foo_bar", 1), { from = 1, to = 6 })
        end)
    end)

    describe("add function", function()
        it("can convert cases", function()
            assert.are.same(augend:add("fooBar", 1, 1), { text = "foo_bar", cursor = 7 })
            assert.are.same(augend:add("fooBar", 2, 1), { cursor = 6 })
            assert.are.same(augend:add("foo_bar", 1, 1), { text = "fooBar", cursor = 6 })
            assert.are.same(augend:add("foo_bar_baz", 1, 1), { text = "fooBarBaz", cursor = 9 })
        end)
    end)
end)
