1
exercism fetch lua bracket-push

bracket-push_spec.lua

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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
local brackets = require('bracket-push')

describe('bracket-push', function()
  it('should accept an empty string', function()
    assert.is_true(brackets.valid(''))
  end)

  it('should accept a matched pair of braces', function()
    assert.is_true(brackets.valid('{}'))
  end)

  it('should reject an opening brace without a closing brace', function()
    assert.is_false(brackets.valid('{'))
  end)

  it('should reject a closing brace without an opening brace', function()
    assert.is_false(brackets.valid('}{'))
  end)

  it('should accept a matched pair of parens', function()
    assert.is_true(brackets.valid('()'))
  end)

  it('should reject an opening paren without a closing paren', function()
    assert.is_false(brackets.valid('('))
  end)

  it('should reject a closing paren without an opening paren', function()
    assert.is_false(brackets.valid(')('))
  end)

  it('should accept a matched pair of square brackets', function()
    assert.is_true(brackets.valid('[]'))
  end)

  it('should reject an opening square bracket without a closing square bracket', function()
    assert.is_false(brackets.valid('['))
  end)

  it('should reject a closing square bracket without an opening square bracket', function()
    assert.is_false(brackets.valid(']['))
  end)

  it('should accept more than one pair of brackets', function()
    assert.is_true(brackets.valid('[]{}()'))
  end)

  it('should accept nested brackets', function()
    assert.is_true(brackets.valid('[{}]'))
  end)

  it('should reject properly balanced but improperly nested brackets', function()
    assert.is_false(brackets.valid('[{]}'))
  end)

  it('should allow deep nesting of brackets', function()
    assert.is_true(brackets.valid('[{(([{}]))}]'))
  end)

  it('should accept complicated brackets that are balanced and properly nested', function()
    assert.is_true(brackets.valid('{[]([()])}'))
  end)

  it('should reject complicated brackets that are not balanced', function()
    assert.is_false(brackets.valid('{[]([()]}'))
  end)

  it('should reject complicated brackets that are not properly nested', function()
    assert.is_false(brackets.valid('{[]([()]})'))
  end)

  it('should ignore non-bracket characters', function()
    assert.is_true(brackets.valid('{hello[]([a()])b}c'))
  end)
end)