aboutsummaryrefslogtreecommitdiffstats
path: root/tests/mason-core/functional/string_spec.lua
blob: 02062f4c6b4c024e46ad48386c326f450e239d1a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
local _ = require "mason-core.functional"

describe("functional: string", function()
    it("matches string patterns", function()
        assert.is_true(_.matches("foo", "foo"))
        assert.is_true(_.matches("bar", "foobarbaz"))
        assert.is_true(_.matches("ba+r", "foobaaaaaaarbaz"))

        assert.is_false(_.matches("ba+r", "foobharbaz"))
        assert.is_false(_.matches("bar", "foobaz"))
    end)

    it("returns string pattern matches", function()
        assert.same({ "foo" }, _.match("foo", "foo"))
        assert.same({ "foo", "bar", "baz" }, _.match("(foo) (bar) (baz)", "foo bar baz"))
    end)

    it("should format strings", function()
        assert.equals("Hello World!", _.format("%s", "Hello World!"))
        assert.equals("special manouvers", _.format("%s manouvers", "special"))
    end)

    it("should split strings", function()
        assert.same({ "This", "is", "a", "sentence" }, _.split("%s", "This is a sentence"))
        assert.same({ "This", "is", "a", "sentence" }, _.split("|", "This|is|a|sentence"))
    end)

    it("should gsub strings", function()
        assert.same("predator", _.gsub("^apex%s*", "", "apex predator"))
    end)

    it("should dedent strings", function()
        assert.equals(
            [[Lorem
Ipsum
    Dolor
  Sit
 Amet]],
            _.dedent [[
    Lorem
    Ipsum
        Dolor
      Sit
     Amet
]]
        )
    end)

    it("should transform casing", function()
        assert.equals("HELLO!", _.to_upper "Hello!")
        assert.equals("hello!", _.to_lower "Hello!")
    end)

    it("trim strings", function()
        assert.equals("HELLO!", _.trim "   HELLO!  ")
    end)

    it("trim_starts strings", function()
        assert.equals("HELLO!  ", _.trim_start("%s", "	   HELLO!  "))
    end)
end)