diff --git a/bin/test b/bin/test new file mode 100755 index 00000000..afcba850 --- /dev/null +++ b/bin/test @@ -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 diff --git a/bin/test-all b/bin/test-all index 505c3f32..4d55b5ba 100755 --- a/bin/test-all +++ b/bin/test-all @@ -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 diff --git a/exercises/practice/acronym/.meta/example.lua b/exercises/practice/acronym/.meta/example.lua index b53c6186..c338c0eb 100644 --- a/exercises/practice/acronym/.meta/example.lua +++ b/exercises/practice/acronym/.meta/example.lua @@ -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) diff --git a/exercises/practice/acronym/.meta/spec_generator.lua b/exercises/practice/acronym/.meta/spec_generator.lua new file mode 100644 index 00000000..140642d1 --- /dev/null +++ b/exercises/practice/acronym/.meta/spec_generator.lua @@ -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 +} diff --git a/exercises/practice/acronym/acronym_spec.lua b/exercises/practice/acronym/acronym_spec.lua index 9c1bf38e..95cf180e 100644 --- a/exercises/practice/acronym/acronym_spec.lua +++ b/exercises/practice/acronym/acronym_spec.lua @@ -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)