Skip to content

Instantly share code, notes, and snippets.

@nb
Created July 3, 2015 13:31
Show Gist options
  • Save nb/0779eab0272bf3172f70 to your computer and use it in GitHub Desktop.
Save nb/0779eab0272bf3172f70 to your computer and use it in GitHub Desktop.
// to run place your solution in index.js and run: babel-node --stage 0 test.js
import assert from 'assert';
import toTitleCase from './index';
const tests = [
{
"input": "follow step-by-step instructions",
"expect": "Follow Step-by-Step Instructions"
},
{
"input": "this sub-phrase is nice",
"expect": "This Sub-Phrase Is Nice"
},
{
"input": "catchy title: a subtitle",
"expect": "Catchy Title: A Subtitle"
},
{
"input": "catchy title: \"a quoted subtitle\"",
"expect": "Catchy Title: \"A Quoted Subtitle\""
},
{
"input": "catchy title: “‘a twice quoted subtitle’”",
"expect": "Catchy Title: “‘A Twice Quoted Subtitle’”"
},
{
"input": "\"a title inside double quotes\"",
"expect": "\"A Title Inside Double Quotes\""
},
{
"input": "all words capitalized",
"expect": "All Words Capitalized"
},
{
"input": "small words are for by and of lowercase",
"expect": "Small Words Are for by and of Lowercase"
},
{
"input": "a small word starts",
"expect": "A Small Word Starts"
},
{
"input": "a small word it ends on",
"expect": "A Small Word It Ends On"
},
{
"input": "do questions work?",
"expect": "Do Questions Work?"
},
{
"input": "multiple sentences. more than one.",
"expect": "Multiple Sentences. More Than One."
},
{
"input": "Ends with small word of",
"expect": "Ends With Small Word Of"
},
{
"input": "double quoted \"inner\" word",
"expect": "Double Quoted \"Inner\" Word"
},
{
"input": "single quoted 'inner' word",
"expect": "Single Quoted 'Inner' Word"
},
{
"input": "fancy double quoted “inner” word",
"expect": "Fancy Double Quoted “Inner” Word"
},
{
"input": "fancy single quoted ‘inner’ word",
"expect": "Fancy Single Quoted ‘Inner’ Word"
},
{
"input": "this vs. that",
"expect": "This vs. That"
},
{
"input": "this vs that",
"expect": "This vs That"
},
{
"input": "this v. that",
"expect": "This v. That"
},
{
"input": "this v that",
"expect": "This v That"
},
{
"input": "address email@example.com titles",
"expect": "Address email@example.com Titles"
},
{
"input": "pass camelCase through",
"expect": "Pass camelCase Through"
},
{
"input": "don't break",
"expect": "Don't Break"
},
{
"input": "catchy title: substance subtitle",
"expect": "Catchy Title: Substance Subtitle"
},
{
"input": "we keep NASA capitalized",
"expect": "We Keep NASA Capitalized"
},
{
"input": "leave Q&A unscathed",
"expect": "Leave Q&A Unscathed"
},
{
"input": "Scott Moritz and TheStreet.com’s million iPhone la-la land",
"expect": "Scott Moritz and TheStreet.com’s Million iPhone La-La Land"
},
{
"input": "you have a http://example.com/foo/ title",
"expect": "You Have a http://example.com/foo/ Title"
},
{
"input": "your hair[cut] looks (nice)",
"expect": "Your Hair[cut] Looks (Nice)"
},
{
"input": "keep that colo(u)r",
"expect": "Keep That Colo(u)r"
},
{
"input": "have you read “The Lottery”?",
"expect": "Have You Read “The Lottery”?"
},
{
"input": "Notes and observations regarding Apple’s announcements from ‘The Beat Goes On’ special event",
"expect": "Notes and Observations Regarding Apple’s Announcements From ‘The Beat Goes On’ Special Event"
}
];
tests.forEach((test) => {
assert(test.expect === toTitleCase(test.input), 'expected ' + test.expect + ', got ' + toTitleCase(test.input));
} );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment