Skip to content

Commit 7ab4430

Browse files
authored
Add spec generator for acronym (#635)
* Add spec generator for acronym * rm -rf
1 parent d42266d commit 7ab4430

File tree

5 files changed

+78
-14
lines changed

5 files changed

+78
-14
lines changed

bin/test

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/usr/bin/env bash
2+
3+
# Runs tests for all provided slugs
4+
5+
RESULT=0
6+
7+
rm -rf test-exercises
8+
cp -r exercises/practice test-exercises
9+
cd test-exercises || exit 1
10+
11+
for i in "$@"
12+
do
13+
if test -d "$i"
14+
then
15+
echo "Testing $i..."
16+
pushd "$i"
17+
mv .meta/example.lua "$i.lua"
18+
busted --verbose || RESULT=1
19+
popd
20+
fi
21+
done
22+
23+
exit $RESULT

bin/test-all

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
RESULT=0
44

5-
rm -r test-exercises
5+
rm -rf test-exercises
66
cp -r exercises/practice test-exercises
77
cd test-exercises || exit 1
88

exercises/practice/acronym/.meta/example.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
return function(s)
22
local letters = {}
3-
s:gsub('[A-Z]*[a-z]*', function(match)
3+
s:gsub("[A-Z]*[a-z']*", function(match)
44
table.insert(letters, match:sub(1, 1):upper())
55
end)
66
return table.concat(letters)
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
return {
2+
module_name = 'acronym',
3+
4+
generate_test = function(case)
5+
local template = [[
6+
local input = "%s"
7+
local expected = '%s'
8+
assert.equal(expected, acronym(input))]]
9+
return template:format(case.input.phrase, case.expected)
10+
end
11+
}
Lines changed: 42 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,57 @@
11
local acronym = require('acronym')
22

33
describe('acronym', function()
4-
it('should generate single-letter acronyms', function()
5-
assert.equal('L', acronym('Lua'))
4+
it('basic', function()
5+
local input = "Portable Network Graphics"
6+
local expected = 'PNG'
7+
assert.equal(expected, acronym(input))
68
end)
79

8-
it('should generate multi-letter acronyms', function()
9-
assert.equal('LUA', acronym('Lua Ultimate Acronym'))
10+
it('lowercase words', function()
11+
local input = "Ruby on Rails"
12+
local expected = 'ROR'
13+
assert.equal(expected, acronym(input))
1014
end)
1115

12-
it('should include lowercase words', function()
13-
assert.equal('ROR', acronym('Ruby on Rails'))
16+
it('punctuation', function()
17+
local input = "First In, First Out"
18+
local expected = 'FIFO'
19+
assert.equal(expected, acronym(input))
1420
end)
1521

16-
it('should ignore punctuation', function()
17-
assert.equal('FIFO', acronym('First In, First Out'))
22+
it('all caps word', function()
23+
local input = "GNU Image Manipulation Program"
24+
local expected = 'GIMP'
25+
assert.equal(expected, acronym(input))
1826
end)
1927

20-
it('should split words with internal capitalization', function()
21-
assert.equal('HTML', acronym('HyperText Markup Language'))
28+
it('punctuation without whitespace', function()
29+
local input = "Complementary metal-oxide semiconductor"
30+
local expected = 'CMOS'
31+
assert.equal(expected, acronym(input))
2232
end)
2333

24-
it('should not split words that are all uppercase', function()
25-
assert.equal('PHP', acronym('PHP: Hypertext Processor'))
34+
it('very long abbreviation', function()
35+
local input = "Rolling On The Floor Laughing So Hard That My Dogs Came Over And Licked Me"
36+
local expected = 'ROTFLSHTMDCOALM'
37+
assert.equal(expected, acronym(input))
38+
end)
39+
40+
it('consecutive delimiters', function()
41+
local input = "Something - I made up from thin air"
42+
local expected = 'SIMUFTA'
43+
assert.equal(expected, acronym(input))
44+
end)
45+
46+
it('apostrophes', function()
47+
local input = "Halley's Comet"
48+
local expected = 'HC'
49+
assert.equal(expected, acronym(input))
50+
end)
51+
52+
it('underscore emphasis', function()
53+
local input = "The Road _Not_ Taken"
54+
local expected = 'TRNT'
55+
assert.equal(expected, acronym(input))
2656
end)
2757
end)

0 commit comments

Comments
 (0)