Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions bin/test
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes it easier to test just one or a small number of exercises

Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/usr/bin/env bash

# Runs tests for all provided slugs

RESULT=0

rm -rf test-exercises
cp -r exercises/practice test-exercises
cd test-exercises || exit 1

for i in "$@"
do
if test -d "$i"
then
echo "Testing $i..."
pushd "$i"
mv .meta/example.lua "$i.lua"
busted --verbose || RESULT=1
popd
fi
done

exit $RESULT
2 changes: 1 addition & 1 deletion bin/test-all
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

RESULT=0

rm -r test-exercises
rm -rf test-exercises
cp -r exercises/practice test-exercises
cd test-exercises || exit 1

Expand Down
2 changes: 1 addition & 1 deletion exercises/practice/acronym/.meta/example.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
return function(s)
local letters = {}
s:gsub('[A-Z]*[a-z]*', function(match)
s:gsub("[A-Z]*[a-z']*", function(match)
table.insert(letters, match:sub(1, 1):upper())
end)
return table.concat(letters)
Expand Down
11 changes: 11 additions & 0 deletions exercises/practice/acronym/.meta/spec_generator.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
return {
module_name = 'acronym',

generate_test = function(case)
local template = [[
local input = "%s"
local expected = '%s'
assert.equal(expected, acronym(input))]]
return template:format(case.input.phrase, case.expected)
end
}
54 changes: 42 additions & 12 deletions exercises/practice/acronym/acronym_spec.lua
Original file line number Diff line number Diff line change
@@ -1,27 +1,57 @@
local acronym = require('acronym')

describe('acronym', function()
it('should generate single-letter acronyms', function()
assert.equal('L', acronym('Lua'))
it('basic', function()
local input = "Portable Network Graphics"
local expected = 'PNG'
assert.equal(expected, acronym(input))
end)

it('should generate multi-letter acronyms', function()
assert.equal('LUA', acronym('Lua Ultimate Acronym'))
it('lowercase words', function()
local input = "Ruby on Rails"
local expected = 'ROR'
assert.equal(expected, acronym(input))
end)

it('should include lowercase words', function()
assert.equal('ROR', acronym('Ruby on Rails'))
it('punctuation', function()
local input = "First In, First Out"
local expected = 'FIFO'
assert.equal(expected, acronym(input))
end)

it('should ignore punctuation', function()
assert.equal('FIFO', acronym('First In, First Out'))
it('all caps word', function()
local input = "GNU Image Manipulation Program"
local expected = 'GIMP'
assert.equal(expected, acronym(input))
end)

it('should split words with internal capitalization', function()
assert.equal('HTML', acronym('HyperText Markup Language'))
it('punctuation without whitespace', function()
local input = "Complementary metal-oxide semiconductor"
local expected = 'CMOS'
assert.equal(expected, acronym(input))
end)

it('should not split words that are all uppercase', function()
assert.equal('PHP', acronym('PHP: Hypertext Processor'))
it('very long abbreviation', function()
local input = "Rolling On The Floor Laughing So Hard That My Dogs Came Over And Licked Me"
local expected = 'ROTFLSHTMDCOALM'
assert.equal(expected, acronym(input))
end)

it('consecutive delimiters', function()
local input = "Something - I made up from thin air"
local expected = 'SIMUFTA'
assert.equal(expected, acronym(input))
end)

it('apostrophes', function()
local input = "Halley's Comet"
local expected = 'HC'
assert.equal(expected, acronym(input))
end)

it('underscore emphasis', function()
local input = "The Road _Not_ Taken"
local expected = 'TRNT'
assert.equal(expected, acronym(input))
end)
end)
Loading