1
exercism fetch lua pig-latin

pig-latin_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
local translate = require('pig-latin')

describe('pig-latin', function()
  it('should append "ay" to words beginning with a vowel', function()
    assert.equal('appleay', translate('apple'))
    assert.equal('earay', translate('ear'))
    assert.equal('iglooay', translate('igloo'))
    assert.equal('objectay', translate('object'))
    assert.equal('underay', translate('under'))
  end)

  it('should move the first letter plus "ay" to the end of words starting with a consonant', function()
    assert.equal('igpay', translate('pig'))
    assert.equal('oalakay', translate('koala'))
    assert.equal('ellowyay', translate('yellow'))
    assert.equal('enonxay', translate('xenon'))
    assert.equal('atqay', translate('qat'))
  end)

  it('should treat "ch" like a single consonant', function()
    assert.equal('airchay', translate('chair'))
  end)

  it('should treat "qu" like a single consonant', function()
    assert.equal('eenquay', translate('queen'))
  end)

  it('should treat a consonant plus "qu" like a single consonant', function()
    assert.equal('aresquay', translate('square'))
  end)

  it('should treat "th" like a single consonant', function()
    assert.equal('erapythay', translate('therapy'))
  end)

  it('should treat "thr" like a single consonant', function()
    assert.equal('ushthray', translate('thrush'))
  end)

  it('should treat "sch" like a single consonant', function()
    assert.equal('oolschay', translate('school'))
  end)

  it('should treat "yt" like a single vowel', function()
    assert.equal('yttriaay', translate('yttria'))
  end)

  it('should treat "xr" like a single vowel', function()
    assert.equal('xrayay', translate('xray'))
  end)

  it('should translate entire phrases', function()
    assert.equal('ickquay astfay unray', translate('quick fast run'))
  end)

  it('should ignore capitalization when translating', function()
    assert.equal('ickQuay aStFay Unray', translate('Quick FaSt rUn'))
  end)

  it('should retain punctuation in translated phrases', function()
    assert.equal('ellway, hatway avehay eway erehay?', translate('well, what have we here?'))
  end)

  it('should retain all whitespace', function()
    assert.equal('abstay\tanday   pacessay', translate('tabs\tand   spaces'))
  end)
end)