Fixed static analysis warnings

This commit is contained in:
thomashii 2021-05-17 23:10:07 +08:00
parent 8e4be01565
commit eb9f79ab85
24 changed files with 624 additions and 629 deletions

View file

@ -1,3 +1,5 @@
include: package:pedantic/analysis_options.yaml
analyzer: analyzer:
strong-mode: strong-mode:
implicit-casts: false implicit-casts: false

View file

@ -1,24 +1,24 @@
import '../lib/inflection3.dart'; import 'package:inflection3/inflection3.dart';
void main() { void main() {
// Using 'shortcut' functions. // Using 'shortcut' functions.
print(pluralize("house")); // => "houses" print(pluralize('house')); // => 'houses'
print(convertToPlural("house")); // => "houses", alias for pluralize print(convertToPlural('house')); // => 'houses', alias for pluralize
print(pluralizeVerb("goes")); // => "go" print(pluralizeVerb('goes')); // => 'go'
print(singularize("axes")); // => "axis" print(singularize('axes')); // => 'axis'
print(convertToSingular("axes")); // => "axis", alias for pluralize print(convertToSingular('axes')); // => 'axis', alias for pluralize
print(singularizeVerb("write")); // => "writes" print(singularizeVerb('write')); // => 'writes'
print(convertToSnakeCase("CamelCaseName")); // => "camel_case_name" print(convertToSnakeCase('CamelCaseName')); // => 'camel_case_name'
print(convertToSpinalCase("CamelCaseName")); // => "camel-case-name" print(convertToSpinalCase('CamelCaseName')); // => 'camel-case-name'
print(past("forgo")); // => "forwent" print(past('forgo')); // => 'forwent'
// Using default encoders. // Using default encoders.
print(PLURAL.convert("virus")); // => "viri" print(PLURAL.convert('virus')); // => 'viri'
print(SINGULAR.convert("Matrices")); // => "Matrix" print(SINGULAR.convert('Matrices')); // => 'Matrix'
print(SINGULAR.convert("species")); // => "species" print(SINGULAR.convert('species')); // => 'species'
print(SNAKE_CASE.convert("CamelCaseName")); // => "camel_case_name" print(SNAKE_CASE.convert('CamelCaseName')); // => 'camel_case_name'
print(SPINAL_CASE.convert("CamelCaseName")); // => "camel-case-name" print(SPINAL_CASE.convert('CamelCaseName')); // => 'camel-case-name'
print(PAST.convert("miss")); // => "missed" print(PAST.convert('miss')); // => 'missed'
} }

View file

@ -2,322 +2,322 @@
/// A collection of verbs with irregular past. /// A collection of verbs with irregular past.
final Map<String, String> irregularPastVerbs = const { final Map<String, String> irregularPastVerbs = const {
"backslidden": "backslid", 'backslidden': 'backslid',
"forbidden": "forbade", 'forbidden': 'forbade',
"stridden": "strode", 'stridden': 'strode',
"stricken": "struck", 'stricken': 'struck',
"brought": "brought", 'brought': 'brought',
"striven": "strove", 'striven': 'strove',
"swollen": "swelled", 'swollen': 'swelled',
"thought": "thought", 'thought': 'thought',
"trodden": "trod", 'trodden': 'trod',
"forbade": "forbade", 'forbade': 'forbade',
"arisen": "arose", 'arisen': 'arose',
"awoken": "awoke", 'awoken': 'awoke',
"beaten": "beat", 'beaten': 'beat',
"became": "became", 'became': 'became',
"become": "became", 'become': 'became',
"bidden": "bid", 'bidden': 'bid',
"bitten": "bit", 'bitten': 'bit',
"broken": "broke", 'broken': 'broke',
"bought": "bought", 'bought': 'bought',
"caught": "caught", 'caught': 'caught',
"choose": "chose", 'choose': 'chose',
"chosen": "chose", 'chosen': 'chose',
"forbid": "forbade", 'forbid': 'forbade',
"dreamt": "dreamt", 'dreamt': 'dreamt',
"driven": "drove", 'driven': 'drove',
"fallen": "fell", 'fallen': 'fell',
"fought": "fought", 'fought': 'fought',
"freeze": "froze", 'freeze': 'froze',
"frozen": "froze", 'frozen': 'froze',
"gotten": "got", 'gotten': 'got',
"ground": "ground", 'ground': 'ground',
"hidden": "hid", 'hidden': 'hid',
"learnt": "learnt", 'learnt': 'learnt',
"proven": "proved", 'proven': 'proved',
"sought": "sought", 'sought': 'sought',
"shaken": "shook", 'shaken': 'shook',
"shaven": "shaved", 'shaven': 'shaved',
"shrank": "shrank", 'shrank': 'shrank',
"shrink": "shrank", 'shrink': 'shrank',
"shrunk": "shrank", 'shrunk': 'shrank',
"spoken": "spoke", 'spoken': 'spoke',
"spoilt": "spoilt", 'spoilt': 'spoilt',
"spread": "spread", 'spread': 'spread',
"sprang": "sprang", 'sprang': 'sprang',
"spring": "sprang", 'spring': 'sprang',
"sprung": "sprang", 'sprung': 'sprang',
"stolen": "stole", 'stolen': 'stole',
"strewn": "strewed", 'strewn': 'strewed',
"strode": "strode", 'strode': 'strode',
"stride": "strode", 'stride': 'strode',
"strike": "struck", 'strike': 'struck',
"strove": "strove", 'strove': 'strove',
"struck": "struck", 'struck': 'struck',
"string": "strung", 'string': 'strung',
"strung": "strung", 'strung': 'strung',
"taught": "taught", 'taught': 'taught',
"thrown": "threw", 'thrown': 'threw',
"thrust": "thrust", 'thrust': 'thrust',
"arise": "arose", 'arise': 'arose',
"arose": "arose", 'arose': 'arose',
"awake": "awoke", 'awake': 'awoke',
"awoke": "awoke", 'awoke': 'awoke',
"borne": "bore", 'borne': 'bore',
"began": "began", 'began': 'began',
"begin": "began", 'begin': 'began',
"begun": "began", 'begun': 'began',
"bound": "bound", 'bound': 'bound',
"bleed": "bled", 'bleed': 'bled',
"blown": "blew", 'blown': 'blew',
"break": "broke", 'break': 'broke',
"breed": "bred", 'breed': 'bred',
"bring": "brought", 'bring': 'brought',
"broke": "broke", 'broke': 'broke',
"build": "built", 'build': 'built',
"built": "built", 'built': 'built',
"burnt": "burnt", 'burnt': 'burnt',
"catch": "caught", 'catch': 'caught',
"chose": "chose", 'chose': 'chose',
"cling": "clung", 'cling': 'clung',
"clung": "clung", 'clung': 'clung',
"creep": "crept", 'creep': 'crept',
"crept": "crept", 'crept': 'crept',
"dealt": "dealt", 'dealt': 'dealt',
"wound": "wound", 'wound': 'wound',
"wring": "wrung", 'wring': 'wrung',
"wrung": "wrung", 'wrung': 'wrung',
"write": "wrote", 'write': 'wrote',
"wrote": "wrote", 'wrote': 'wrote',
"drawn": "drew", 'drawn': 'drew',
"drank": "drank", 'drank': 'drank',
"drink": "drank", 'drink': 'drank',
"drunk": "drank", 'drunk': 'drank',
"drive": "drove", 'drive': 'drove',
"drove": "drove", 'drove': 'drove',
"dwelt": "dwelt", 'dwelt': 'dwelt',
"eaten": "ate", 'eaten': 'ate',
"fight": "fought", 'fight': 'fought',
"found": "found", 'found': 'found',
"fling": "flung", 'fling': 'flung',
"flung": "flung", 'flung': 'flung',
"flown": "flew", 'flown': 'flew',
"froze": "froze", 'froze': 'froze',
"given": "gave", 'given': 'gave',
"grind": "ground", 'grind': 'ground',
"grown": "grew", 'grown': 'grew',
"heard": "heard", 'heard': 'heard',
"knelt": "knelt", 'knelt': 'knelt',
"known": "knew", 'known': 'knew',
"leant": "leant", 'leant': 'leant',
"leapt": "leapt", 'leapt': 'leapt',
"leave": "left", 'leave': 'left',
"meant": "meant", 'meant': 'meant',
"risen": "rose", 'risen': 'rose',
"shake": "shook", 'shake': 'shook',
"shorn": "sheared", 'shorn': 'sheared',
"shone": "shone", 'shone': 'shone',
"shook": "shook", 'shook': 'shook',
"shoot": "shot", 'shoot': 'shot',
"shown": "showed", 'shown': 'showed',
"slain": "slew", 'slain': 'slew',
"sleep": "slept", 'sleep': 'slept',
"slept": "slept", 'slept': 'slept',
"slide": "slid", 'slide': 'slid',
"sling": "slung", 'sling': 'slung',
"slung": "slung", 'slung': 'slung',
"slunk": "slunk", 'slunk': 'slunk',
"smelt": "smelt", 'smelt': 'smelt',
"snuck": "snuck", 'snuck': 'snuck',
"speak": "spoke", 'speak': 'spoke',
"spelt": "spelt", 'spelt': 'spelt',
"spend": "spent", 'spend': 'spent',
"spent": "spent", 'spent': 'spent',
"spilt": "spilt", 'spilt': 'spilt',
"split": "split", 'split': 'split',
"spoke": "spoke", 'spoke': 'spoke',
"stand": "stood", 'stand': 'stood',
"stood": "stood", 'stood': 'stood',
"steal": "stole", 'steal': 'stole',
"stick": "stuck", 'stick': 'stuck',
"stole": "stole", 'stole': 'stole',
"stuck": "stuck", 'stuck': 'stuck',
"sting": "stung", 'sting': 'stung',
"stung": "stung", 'stung': 'stung',
"stank": "stank", 'stank': 'stank',
"stink": "stank", 'stink': 'stank',
"stunk": "stank", 'stunk': 'stank',
"swear": "swore", 'swear': 'swore',
"swore": "swore", 'swore': 'swore',
"sworn": "swore", 'sworn': 'swore',
"sweep": "swept", 'sweep': 'swept',
"swept": "swept", 'swept': 'swept',
"swing": "swung", 'swing': 'swung',
"swung": "swung", 'swung': 'swung',
"taken": "took", 'taken': 'took',
"teach": "taught", 'teach': 'taught',
"think": "thought", 'think': 'thought',
"threw": "threw", 'threw': 'threw',
"throw": "threw", 'throw': 'threw',
"tread": "trod", 'tread': 'trod',
"wake": "woke", 'wake': 'woke',
"woken": "woke", 'woken': 'woke',
"woven": "wove", 'woven': 'wove',
"bear": "bore", 'bear': 'bore',
"bore": "bore", 'bore': 'bore',
"born": "bore", 'born': 'bore',
"beat": "beat", 'beat': 'beat',
"bend": "bent", 'bend': 'bent',
"bent": "bent", 'bent': 'bent',
"bind": "bound", 'bind': 'bound',
"bite": "bit", 'bite': 'bit',
"bled": "bled", 'bled': 'bled',
"blew": "blew", 'blew': 'blew',
"blow": "blew", 'blow': 'blew',
"bred": "bred", 'bred': 'bred',
"cast": "cast", 'cast': 'cast',
"clad": "clad", 'clad': 'clad',
"come": "came", 'come': 'came',
"cost": "cost", 'cost': 'cost',
"deal": "dealt", 'deal': 'dealt',
"does": "did", 'does': 'did',
"done": "did", 'done': 'did',
"draw": "drew", 'draw': 'drew',
"drew": "drew", 'drew': 'drew',
"fall": "fell", 'fall': 'fell',
"feed": "fed", 'feed': 'fed',
"feel": "felt", 'feel': 'felt',
"fell": "fell", 'fell': 'fell',
"felt": "felt", 'felt': 'felt',
"find": "found", 'find': 'found',
"flee": "fled", 'flee': 'fled',
"fled": "fled", 'fled': 'fled',
"flew": "flew", 'flew': 'flew',
"gave": "gave", 'gave': 'gave',
"give": "gave", 'give': 'gave',
"gone": "went", 'gone': 'went',
"grew": "grew", 'grew': 'grew',
"grow": "grew", 'grow': 'grew',
"hang": "hung", 'hang': 'hung',
"hung": "hung", 'hung': 'hung',
"have": "had", 'have': 'had',
"hear": "heard", 'hear': 'heard',
"hewn": "hewed", 'hewn': 'hewed',
"hide": "hid", 'hide': 'hid',
"hold": "held", 'hold': 'held',
"held": "held", 'held': 'held',
"hurt": "hurt", 'hurt': 'hurt',
"keep": "kept", 'keep': 'kept',
"kept": "kept", 'kept': 'kept',
"knew": "knew", 'knew': 'knew',
"know": "knew", 'know': 'knew',
"laid": "laid", 'laid': 'laid',
"lead": "led", 'lead': 'led',
"left": "left", 'left': 'left',
"lend": "lent", 'lend': 'lent',
"lent": "lent", 'lent': 'lent',
"lain": "lay", 'lain': 'lay',
"lose": "lost", 'lose': 'lost',
"lost": "lost", 'lost': 'lost',
"make": "made", 'make': 'made',
"made": "made", 'made': 'made',
"mean": "meant", 'mean': 'meant',
"meet": "met", 'meet': 'met',
"mown": "mowed", 'mown': 'mowed',
"paid": "paid", 'paid': 'paid',
"pled": "pled", 'pled': 'pled',
"read": "read", 'read': 'read',
"ride": "rode", 'ride': 'rode',
"rode": "rode", 'rode': 'rode',
"ring": "rang", 'ring': 'rang',
"rung": "rang", 'rung': 'rang',
"rise": "rose", 'rise': 'rose',
"rose": "rose", 'rose': 'rose',
"sang": "sang", 'sang': 'sang',
"sawn": "sawed", 'sawn': 'sawed',
"said": "said", 'said': 'said',
"seen": "saw", 'seen': 'saw',
"seek": "sought", 'seek': 'sought',
"sell": "sold", 'sell': 'sold',
"slew": "slew", 'slew': 'slew',
"sold": "sold", 'sold': 'sold',
"send": "sent", 'send': 'sent',
"sent": "sent", 'sent': 'sent',
"sewn": "sewed", 'sewn': 'sewed',
"shed": "shed", 'shed': 'shed',
"shot": "shot", 'shot': 'shot',
"shut": "shut", 'shut': 'shut',
"sing": "sang", 'sing': 'sang',
"sung": "sang", 'sung': 'sang',
"slid": "slid", 'slid': 'slid',
"slit": "slit", 'slit': 'slit',
"sown": "sowed", 'sown': 'sowed',
"sped": "sped", 'sped': 'sped',
"spin": "spun", 'spin': 'spun',
"spun": "spun", 'spun': 'spun',
"spit": "spit", 'spit': 'spit',
"spat": "spat", 'spat': 'spat',
"swam": "swam", 'swam': 'swam',
"swim": "swam", 'swim': 'swam',
"swum": "swam", 'swum': 'swam',
"take": "took", 'take': 'took',
"tear": "tore", 'tear': 'tore',
"tore": "tore", 'tore': 'tore',
"torn": "tore", 'torn': 'tore',
"tell": "told", 'tell': 'told',
"told": "told", 'told': 'told',
"took": "took", 'took': 'took',
"trod": "trod", 'trod': 'trod',
"wear": "wore", 'wear': 'wore',
"wore": "wore", 'wore': 'wore',
"worn": "wore", 'worn': 'wore',
"weep": "wept", 'weep': 'wept',
"went": "went", 'went': 'went',
"wept": "wept", 'wept': 'wept',
"were": "were", 'were': 'were',
"wind": "wound", 'wind': 'wound',
"woke": "woke", 'woke': 'woke',
"wove": "wove", 'wove': 'wove',
"are": "were", 'are': 'were',
"ate": "ate", 'ate': 'ate',
"bet": "bet", 'bet': 'bet',
"bid": "bid", 'bid': 'bid',
"bit": "bit", 'bit': 'bit',
"buy": "bought", 'buy': 'bought',
"cut": "cut", 'cut': 'cut',
"did": "did", 'did': 'did',
"dig": "dug", 'dig': 'dug',
"dug": "dug", 'dug': 'dug',
"eat": "ate", 'eat': 'ate',
"fed": "fed", 'fed': 'fed',
"fly": "flew", 'fly': 'flew',
"get": "got", 'get': 'got',
"got": "got", 'got': 'got',
"had": "had", 'had': 'had',
"has": "had", 'has': 'had',
"hid": "hid", 'hid': 'hid',
"hit": "hit", 'hit': 'hit',
"lay": "laid", 'lay': 'laid',
"led": "led", 'led': 'led',
"let": "let", 'let': 'let',
"lit": "lit", 'lit': 'lit',
"met": "met", 'met': 'met',
"pay": "paid", 'pay': 'paid',
"put": "put", 'put': 'put',
"ran": "ran", 'ran': 'ran',
"rid": "rid", 'rid': 'rid',
"run": "ran", 'run': 'ran',
"saw": "saw", 'saw': 'saw',
"say": "said", 'say': 'said',
"see": "saw", 'see': 'saw',
"sit": "sat", 'sit': 'sat',
"sat": "sat", 'sat': 'sat',
"set": "set", 'set': 'set',
"was": "was", 'was': 'was',
"win": "won", 'win': 'won',
"won": "won", 'won': 'won',
"do": "did", 'do': 'did',
"go": "went", 'go': 'went',
"is": "was", 'is': 'was',
}; };

View file

@ -4,8 +4,8 @@
/// ///
/// [A List of 100 Irregular Plural Nouns in English](http://grammar.about.com/od/words/a/A-List-Of-Irregular-Plural-Nouns-In-English.htm) /// [A List of 100 Irregular Plural Nouns in English](http://grammar.about.com/od/words/a/A-List-Of-Irregular-Plural-Nouns-In-English.htm)
final Map<String, String> irregularPluralNouns = const { final Map<String, String> irregularPluralNouns = const {
"person": "people", 'person': 'people',
"man": "men", 'man': 'men',
"child": "children", 'child': 'children',
"sex": "sexes" 'sex': 'sexes'
}; };

View file

@ -2,8 +2,8 @@
/// A collection of verbs with irregular plurals. /// A collection of verbs with irregular plurals.
final Map<String, String> irregularPluralVerbs = const { final Map<String, String> irregularPluralVerbs = const {
"is": "are", 'is': 'are',
"am": "are", 'am': 'are',
"was": "were", 'was': 'were',
"has": "have" 'has': 'have'
}; };

View file

@ -25,12 +25,12 @@ class PastEncoder extends Converter<String, String> {
void addInflectionRule(String presentOrParticiple, dynamic past) { void addInflectionRule(String presentOrParticiple, dynamic past) {
_inflectionRules _inflectionRules
.add([new RegExp(presentOrParticiple, caseSensitive: false), past]); .add([RegExp(presentOrParticiple, caseSensitive: false), past]);
} }
void addIrregularInflectionRule(String presentOrParticiple, String past) { void addIrregularInflectionRule(String presentOrParticiple, String past) {
_inflectionRules.add([ _inflectionRules.add([
new RegExp( RegExp(
r'^(back|dis|for|fore|in|inter|mis|off|over|out|par|pre|re|type|un|under|up)?' + r'^(back|dis|for|fore|in|inter|mis|off|over|out|par|pre|re|type|un|under|up)?' +
presentOrParticiple + presentOrParticiple +
r'$', r'$',
@ -41,13 +41,14 @@ class PastEncoder extends Converter<String, String> {
@override @override
String convert(String word) { String convert(String word) {
if (!word.isEmpty) { if (word.isNotEmpty) {
if (word.contains("ed", word.length - 2)) { if (word.contains('ed', word.length - 2)) {
RegExp reg = new RegExp( var reg = RegExp(
r'^(back|dis|for|fore|in|inter|mis|off|over|out|par|pre|re|type|un|under|up)(.+)$'); r'^(back|dis|for|fore|in|inter|mis|off|over|out|par|pre|re|type|un|under|up)(.+)$');
if (reg.hasMatch(word)) { if (reg.hasMatch(word)) {
if (!verbsEndingWithEd.contains(reg.firstMatch(word)!.group(2))) if (!verbsEndingWithEd.contains(reg.firstMatch(word)!.group(2))) {
return word; return word;
}
} else if (!verbsEndingWithEd.contains(word)) { } else if (!verbsEndingWithEd.contains(word)) {
return word; return word;
} }
@ -65,4 +66,4 @@ class PastEncoder extends Converter<String, String> {
} }
} }
final Converter<String, String> PAST = new PastEncoder(); final Converter<String, String> PAST = PastEncoder();

View file

@ -41,7 +41,7 @@ class PluralEncoder extends Converter<String, String> {
} }
void addInflectionRule(String singular, dynamic plural) { void addInflectionRule(String singular, dynamic plural) {
_inflectionRules.add([new RegExp(singular, caseSensitive: false), plural]); _inflectionRules.add([RegExp(singular, caseSensitive: false), plural]);
} }
void addIrregularInflectionRule(String singular, String plural) { void addIrregularInflectionRule(String singular, String plural) {
@ -51,23 +51,23 @@ class PluralEncoder extends Converter<String, String> {
final prest = plural.substring(1); final prest = plural.substring(1);
if (s0.toUpperCase() == p0.toUpperCase()) { if (s0.toUpperCase() == p0.toUpperCase()) {
addInflectionRule('(${s0})${srest}\$', (Match m) => '${m[1]}${prest}'); addInflectionRule('($s0)$srest\$', (Match m) => '${m[1]}$prest');
addInflectionRule('(${p0})${prest}\$', (Match m) => '${m[1]}${prest}'); addInflectionRule('($p0)$prest\$', (Match m) => '${m[1]}$prest');
} else { } else {
addInflectionRule('${s0.toUpperCase()}(?i)${srest}\$', addInflectionRule('${s0.toUpperCase()}(?i)$srest\$',
(Match m) => '${p0.toUpperCase()}${prest}'); (Match m) => '${p0.toUpperCase()}$prest');
addInflectionRule('${s0.toLowerCase()}(?i)${srest}\$', addInflectionRule('${s0.toLowerCase()}(?i)$srest\$',
(Match m) => '${p0.toUpperCase()}${prest}'); (Match m) => '${p0.toUpperCase()}$prest');
addInflectionRule('${p0.toUpperCase()}(?i)${prest}\$', addInflectionRule('${p0.toUpperCase()}(?i)$prest\$',
(Match m) => '${p0.toUpperCase()}${prest}'); (Match m) => '${p0.toUpperCase()}$prest');
addInflectionRule('${p0.toLowerCase()}(?i)${prest}\$', addInflectionRule('${p0.toLowerCase()}(?i)$prest\$',
(Match m) => '${p0.toLowerCase()}${prest}'); (Match m) => '${p0.toLowerCase()}$prest');
} }
} }
@override @override
String convert(String word) { String convert(String word) {
if (!word.isEmpty) { if (word.isNotEmpty) {
if (uncountableNouns.contains(word.toLowerCase())) { if (uncountableNouns.contains(word.toLowerCase())) {
return word; return word;
} else { } else {
@ -84,4 +84,4 @@ class PluralEncoder extends Converter<String, String> {
} }
} }
final Converter<String, String> PLURAL = new PluralEncoder(); final Converter<String, String> PLURAL = PluralEncoder();

View file

@ -28,12 +28,12 @@ class PluralVerbEncoder extends Converter<String, String> {
} }
void addInflectionRule(String singular, dynamic plural) { void addInflectionRule(String singular, dynamic plural) {
_inflectionRules.add([new RegExp(singular, caseSensitive: false), plural]); _inflectionRules.add([RegExp(singular, caseSensitive: false), plural]);
} }
@override @override
String convert(String word) { String convert(String word) {
if (!word.isEmpty) { if (word.isNotEmpty) {
for (var r in _inflectionRules) { for (var r in _inflectionRules) {
var pattern = r.first as RegExp; var pattern = r.first as RegExp;
if (pattern.hasMatch(word)) { if (pattern.hasMatch(word)) {
@ -46,4 +46,4 @@ class PluralVerbEncoder extends Converter<String, String> {
} }
} }
final Converter<String, String> PLURALVERB = new PluralVerbEncoder(); final Converter<String, String> PLURALVERB = PluralVerbEncoder();

View file

@ -49,7 +49,7 @@ class SingularEncoder extends Converter<String, String> {
} }
void addInflectionRule(String plural, dynamic singular) { void addInflectionRule(String plural, dynamic singular) {
_inflectionRules.add([new RegExp(plural, caseSensitive: false), singular]); _inflectionRules.add([RegExp(plural, caseSensitive: false), singular]);
} }
void addIrregularInflectionRule(String singular, String plural) { void addIrregularInflectionRule(String singular, String plural) {
@ -59,23 +59,23 @@ class SingularEncoder extends Converter<String, String> {
final prest = plural.substring(1); final prest = plural.substring(1);
if (s0.toUpperCase() == p0.toUpperCase()) { if (s0.toUpperCase() == p0.toUpperCase()) {
addInflectionRule('(${s0})${srest}\$', (Match m) => '${m[1]}${srest}'); addInflectionRule('($s0)$srest\$', (Match m) => '${m[1]}$srest');
addInflectionRule('(${p0})${prest}\$', (Match m) => '${m[1]}${srest}'); addInflectionRule('($p0)$prest\$', (Match m) => '${m[1]}$srest');
} else { } else {
addInflectionRule('${s0.toUpperCase()}(?i)${srest}\$', addInflectionRule('${s0.toUpperCase()}(?i)$srest\$',
(Match m) => '${s0.toUpperCase()}${srest}'); (Match m) => '${s0.toUpperCase()}$srest');
addInflectionRule('${s0.toLowerCase()}(?i)${srest}\$', addInflectionRule('${s0.toLowerCase()}(?i)$srest\$',
(Match m) => '${s0.toUpperCase()}${srest}'); (Match m) => '${s0.toUpperCase()}$srest');
addInflectionRule('${p0.toUpperCase()}(?i)${prest}\$', addInflectionRule('${p0.toUpperCase()}(?i)$prest\$',
(Match m) => '${s0.toUpperCase()}${srest}'); (Match m) => '${s0.toUpperCase()}$srest');
addInflectionRule('${p0.toLowerCase()}(?i)${prest}\$', addInflectionRule('${p0.toLowerCase()}(?i)$prest\$',
(Match m) => '${s0.toLowerCase()}${srest}'); (Match m) => '${s0.toLowerCase()}$srest');
} }
} }
@override @override
String convert(String word) { String convert(String word) {
if (!word.isEmpty) { if (word.isNotEmpty) {
if (uncountableNouns.contains(word.toLowerCase())) { if (uncountableNouns.contains(word.toLowerCase())) {
return word; return word;
} else { } else {
@ -92,4 +92,4 @@ class SingularEncoder extends Converter<String, String> {
} }
} }
final Converter<String, String> SINGULAR = new SingularEncoder(); final Converter<String, String> SINGULAR = SingularEncoder();

View file

@ -25,12 +25,12 @@ class SingularVerbEncoder extends Converter<String, String> {
} }
void addInflectionRule(String singular, dynamic plural) { void addInflectionRule(String singular, dynamic plural) {
_inflectionRules.add([new RegExp(singular, caseSensitive: false), plural]); _inflectionRules.add([RegExp(singular, caseSensitive: false), plural]);
} }
@override @override
String convert(String word) { String convert(String word) {
if (!word.isEmpty) { if (word.isNotEmpty) {
for (var r in _inflectionRules) { for (var r in _inflectionRules) {
var pattern = r.first as RegExp; var pattern = r.first as RegExp;
if (pattern.hasMatch(word)) { if (pattern.hasMatch(word)) {
@ -43,4 +43,4 @@ class SingularVerbEncoder extends Converter<String, String> {
} }
} }
final Converter<String, String> SINGULARVERB = new SingularVerbEncoder(); final Converter<String, String> SINGULARVERB = SingularVerbEncoder();

View file

@ -2,9 +2,9 @@
import 'dart:convert'; import 'dart:convert';
final _underscoreRE0 = new RegExp(r'''([A-Z\d]+)([A-Z][a-z])'''); final _underscoreRE0 = RegExp(r'''([A-Z\d]+)([A-Z][a-z])''');
final _underscoreRE1 = new RegExp(r'''([a-z\d])([A-Z])'''); final _underscoreRE1 = RegExp(r'''([a-z\d])([A-Z])''');
final _underscoreRE2 = new RegExp(r'[-\s]'); final _underscoreRE2 = RegExp(r'[-\s]');
class SnakeCaseEncoder extends Converter<String, String> { class SnakeCaseEncoder extends Converter<String, String> {
const SnakeCaseEncoder(); const SnakeCaseEncoder();
@ -14,11 +14,11 @@ class SnakeCaseEncoder extends Converter<String, String> {
@override @override
String convert(String phrase) { String convert(String phrase) {
return phrase return phrase
.replaceAllMapped(_underscoreRE0, (match) => "${match[1]}_${match[2]}") .replaceAllMapped(_underscoreRE0, (match) => '${match[1]}_${match[2]}')
.replaceAllMapped(_underscoreRE1, (match) => "${match[1]}_${match[2]}") .replaceAllMapped(_underscoreRE1, (match) => '${match[1]}_${match[2]}')
.replaceAll(_underscoreRE2, "_") .replaceAll(_underscoreRE2, '_')
.toLowerCase(); .toLowerCase();
} }
} }
const Converter<String, String> SNAKE_CASE = const SnakeCaseEncoder(); const Converter<String, String> SNAKE_CASE = SnakeCaseEncoder();

View file

@ -2,9 +2,9 @@
import 'dart:convert'; import 'dart:convert';
final _underscoreRE0 = new RegExp(r'''([A-Z\d]+)([A-Z][a-z])'''); final _underscoreRE0 = RegExp(r'''([A-Z\d]+)([A-Z][a-z])''');
final _underscoreRE1 = new RegExp(r'''([a-z\d])([A-Z])'''); final _underscoreRE1 = RegExp(r'''([a-z\d])([A-Z])''');
final _underscoreRE2 = new RegExp(r'[_\s]'); final _underscoreRE2 = RegExp(r'[_\s]');
class SpinalCaseEncoder extends Converter<String, String> { class SpinalCaseEncoder extends Converter<String, String> {
const SpinalCaseEncoder(); const SpinalCaseEncoder();
@ -14,11 +14,11 @@ class SpinalCaseEncoder extends Converter<String, String> {
@override @override
String convert(String phrase) { String convert(String phrase) {
return phrase return phrase
.replaceAllMapped(_underscoreRE0, (match) => "${match[1]}-${match[2]}") .replaceAllMapped(_underscoreRE0, (match) => '${match[1]}-${match[2]}')
.replaceAllMapped(_underscoreRE1, (match) => "${match[1]}-${match[2]}") .replaceAllMapped(_underscoreRE1, (match) => '${match[1]}-${match[2]}')
.replaceAll(_underscoreRE2, "-") .replaceAll(_underscoreRE2, '-')
.toLowerCase(); .toLowerCase();
} }
} }
const Converter<String, String> SPINAL_CASE = const SpinalCaseEncoder(); const Converter<String, String> SPINAL_CASE = SpinalCaseEncoder();

View file

@ -1,16 +1,16 @@
//library inflection2.uncountable; //library inflection2.uncountable;
/// Uncountable nouns are substances, concepts etc that we cannot divide into /// Uncountable nouns are substances, concepts etc that we cannot divide into
/// separate elements. We cannot "count" them. /// separate elements. We cannot 'count' them.
final Set<String> uncountableNouns = new Set.from(const [ final Set<String> uncountableNouns = Set.from(const [
"equipment", 'equipment',
"information", 'information',
"rice", 'rice',
"money", 'money',
"species", 'species',
"series", 'series',
"fish", 'fish',
"sheep", 'sheep',
"jeans", 'jeans',
"police" 'police'
]); ]);

View file

@ -2,20 +2,20 @@
/// A collection of verbs ending with -ed. /// A collection of verbs ending with -ed.
final List<String> verbsEndingWithEd = const [ final List<String> verbsEndingWithEd = const [
"bed", 'bed',
"bleed", 'bleed',
"breed", 'breed',
"embed", 'embed',
"exceed", 'exceed',
"feed", 'feed',
"heed", 'heed',
"need", 'need',
"proceed", 'proceed',
"seed", 'seed',
"shred" 'shred',
"speed", 'speed',
"succeed", 'succeed',
"ted", 'ted',
"wed", 'wed',
"weed" 'weed'
]; ];

View file

@ -6,3 +6,4 @@ environment:
sdk: '>=2.12.0 <3.0.0' sdk: '>=2.12.0 <3.0.0'
dev_dependencies: dev_dependencies:
test: ^1.17.4 test: ^1.17.4
pedantic: ^1.11.0

View file

@ -1,18 +1,17 @@
library inflection3.test; library inflection3.test;
import 'package:test/test.dart'; import 'package:test/test.dart';
import 'package:inflection3/inflection3.dart';
import '../lib/inflection3.dart';
void main() { void main() {
group("The inflection library", () { group('The inflection library', () {
test("provides a few convenient helper functions", () { test('provides a few convenient helper functions', () {
expect(pluralize("axis"), equals("axes")); expect(pluralize('axis'), equals('axes'));
expect(convertToPlural("axis"), equals("axes")); expect(convertToPlural('axis'), equals('axes'));
expect(singularize("Houses"), equals("House")); expect(singularize('Houses'), equals('House'));
expect(convertToSingular("Houses"), equals("House")); expect(convertToSingular('Houses'), equals('House'));
expect(convertToSnakeCase("CamelCase"), equals("camel_case")); expect(convertToSnakeCase('CamelCase'), equals('camel_case'));
expect(convertToSpinalCase("CamelCase"), equals("camel-case")); expect(convertToSpinalCase('CamelCase'), equals('camel-case'));
}); });
}); });
} }

View file

@ -1,11 +1,10 @@
library inflection3.is_tense.test; library inflection3.is_tense.test;
import 'package:test/test.dart'; import 'package:test/test.dart';
import 'package:inflection3/inflection3.dart';
import '../lib/inflection3.dart';
void main() { void main() {
group("isTense", () { group('isTense', () {
test('correctly identifies if a word is in past tense', () { test('correctly identifies if a word is in past tense', () {
expect(isPastTense('run'), false); expect(isPastTense('run'), false);
expect(isPastTense('ran'), true); expect(isPastTense('ran'), true);

View file

@ -1,46 +1,45 @@
library inflection3.past.test; library inflection3.past.test;
import 'package:inflection3/inflection3.dart';
import 'package:inflection3/src/irregular_past_verbs.dart';
import 'package:test/test.dart'; import 'package:test/test.dart';
import '../lib/src/irregular_past_verbs.dart';
import '../lib/src/past.dart';
void main() { void main() {
group("The PastEncoder", () { group('The PastEncoder', () {
test("converts verbs from present or participle to past", () { test('converts verbs from present or participle to past', () {
expect(PAST.convert(""), equals("")); expect(PAST.convert(''), equals(''));
expect(PAST.convert("ask"), equals("asked")); expect(PAST.convert('ask'), equals('asked'));
expect(PAST.convert("close"), equals("closed")); expect(PAST.convert('close'), equals('closed'));
expect(PAST.convert("die"), equals("died")); expect(PAST.convert('die'), equals('died'));
expect(PAST.convert("phone"), equals("phoned")); expect(PAST.convert('phone'), equals('phoned'));
expect(PAST.convert("play"), equals("played")); expect(PAST.convert('play'), equals('played'));
expect(PAST.convert("destroy"), equals("destroyed")); expect(PAST.convert('destroy'), equals('destroyed'));
expect(PAST.convert("show"), equals("showed")); expect(PAST.convert('show'), equals('showed'));
expect(PAST.convert("marry"), equals("married")); expect(PAST.convert('marry'), equals('married'));
expect(PAST.convert("study"), equals("studied")); expect(PAST.convert('study'), equals('studied'));
expect(PAST.convert("visit"), equals("visited")); expect(PAST.convert('visit'), equals('visited'));
expect(PAST.convert("miss"), equals("missed")); expect(PAST.convert('miss'), equals('missed'));
expect(PAST.convert("watch"), equals("watched")); expect(PAST.convert('watch'), equals('watched'));
expect(PAST.convert("finish"), equals("finished")); expect(PAST.convert('finish'), equals('finished'));
expect(PAST.convert("fix"), equals("fixed")); expect(PAST.convert('fix'), equals('fixed'));
expect(PAST.convert("buzz"), equals("buzzed")); expect(PAST.convert('buzz'), equals('buzzed'));
expect(PAST.convert("asked"), equals("asked")); expect(PAST.convert('asked'), equals('asked'));
expect(PAST.convert("closed"), equals("closed")); expect(PAST.convert('closed'), equals('closed'));
expect(PAST.convert("reopened"), equals("reopened")); expect(PAST.convert('reopened'), equals('reopened'));
expect(PAST.convert("unseed"), equals("unseeded")); expect(PAST.convert('unseed'), equals('unseeded'));
}); });
test("handles irregular past verbs", () { test('handles irregular past verbs', () {
irregularPastVerbs.forEach((String presentOrParticiple, String past) { irregularPastVerbs.forEach((String presentOrParticiple, String past) {
expect(PAST.convert(presentOrParticiple), equals(past)); expect(PAST.convert(presentOrParticiple), equals(past));
}); });
expect(PAST.convert("forgo"), equals("forwent")); expect(PAST.convert('forgo'), equals('forwent'));
expect(PAST.convert("undo"), equals("undid")); expect(PAST.convert('undo'), equals('undid'));
expect(PAST.convert("outsell"), equals("outsold")); expect(PAST.convert('outsell'), equals('outsold'));
expect(PAST.convert("rebreed"), equals("rebred")); expect(PAST.convert('rebreed'), equals('rebred'));
expect(PAST.convert("arose"), equals("arose")); expect(PAST.convert('arose'), equals('arose'));
expect(PAST.convert("backslid"), equals("backslid")); expect(PAST.convert('backslid'), equals('backslid'));
expect(PAST.convert("forbade"), equals("forbade")); expect(PAST.convert('forbade'), equals('forbade'));
}); });
}); });
} }

View file

@ -1,51 +1,50 @@
library inflection3.plural.test; library inflection3.plural.test;
import 'package:inflection3/inflection3.dart';
import 'package:inflection3/src/uncountable_nouns.dart';
import 'package:test/test.dart'; import 'package:test/test.dart';
import '../lib/inflection3.dart';
import '../lib/src/uncountable_nouns.dart';
void main() { void main() {
group("The PluralEncoder", () { group('The PluralEncoder', () {
test("converts nouns from singular to plural", () { test('converts nouns from singular to plural', () {
expect(PLURAL.convert(""), equals("")); expect(PLURAL.convert(''), equals(''));
expect(PLURAL.convert("House"), equals("Houses")); expect(PLURAL.convert('House'), equals('Houses'));
expect(PLURAL.convert("house"), equals("houses")); expect(PLURAL.convert('house'), equals('houses'));
expect(PLURAL.convert("dog"), equals("dogs")); expect(PLURAL.convert('dog'), equals('dogs'));
expect(PLURAL.convert("axis"), equals("axes")); expect(PLURAL.convert('axis'), equals('axes'));
expect(PLURAL.convert("testis"), equals("testes")); expect(PLURAL.convert('testis'), equals('testes'));
expect(PLURAL.convert("octopus"), equals("octopi")); expect(PLURAL.convert('octopus'), equals('octopi'));
expect(PLURAL.convert("virus"), equals("viri")); expect(PLURAL.convert('virus'), equals('viri'));
expect(PLURAL.convert("octopi"), equals("octopi")); expect(PLURAL.convert('octopi'), equals('octopi'));
expect(PLURAL.convert("viri"), equals("viri")); expect(PLURAL.convert('viri'), equals('viri'));
expect(PLURAL.convert("alias"), equals("aliases")); expect(PLURAL.convert('alias'), equals('aliases'));
expect(PLURAL.convert("status"), equals("statuses")); expect(PLURAL.convert('status'), equals('statuses'));
expect(PLURAL.convert("bus"), equals("buses")); expect(PLURAL.convert('bus'), equals('buses'));
expect(PLURAL.convert("buffalo"), equals("buffaloes")); expect(PLURAL.convert('buffalo'), equals('buffaloes'));
expect(PLURAL.convert("tomato"), equals("tomatoes")); expect(PLURAL.convert('tomato'), equals('tomatoes'));
expect(PLURAL.convert("ultimatum"), equals("ultimata")); expect(PLURAL.convert('ultimatum'), equals('ultimata'));
expect(PLURAL.convert("pentium"), equals("pentia")); expect(PLURAL.convert('pentium'), equals('pentia'));
expect(PLURAL.convert("ultimata"), equals("ultimata")); expect(PLURAL.convert('ultimata'), equals('ultimata'));
expect(PLURAL.convert("pentia"), equals("pentia")); expect(PLURAL.convert('pentia'), equals('pentia'));
expect(PLURAL.convert("nemesis"), equals("nemeses")); expect(PLURAL.convert('nemesis'), equals('nemeses'));
expect(PLURAL.convert("hive"), equals("hives")); expect(PLURAL.convert('hive'), equals('hives'));
expect(PLURAL.convert("fly"), equals("flies")); expect(PLURAL.convert('fly'), equals('flies'));
expect(PLURAL.convert("dish"), equals("dishes")); expect(PLURAL.convert('dish'), equals('dishes'));
expect(PLURAL.convert("bench"), equals("benches")); expect(PLURAL.convert('bench'), equals('benches'));
expect(PLURAL.convert("matrix"), equals("matrices")); expect(PLURAL.convert('matrix'), equals('matrices'));
expect(PLURAL.convert("vertex"), equals("vertices")); expect(PLURAL.convert('vertex'), equals('vertices'));
expect(PLURAL.convert("index"), equals("indices")); expect(PLURAL.convert('index'), equals('indices'));
expect(PLURAL.convert("mouse"), equals("mice")); expect(PLURAL.convert('mouse'), equals('mice'));
expect(PLURAL.convert("louse"), equals("lice")); expect(PLURAL.convert('louse'), equals('lice'));
expect(PLURAL.convert("mice"), equals("mice")); expect(PLURAL.convert('mice'), equals('mice'));
expect(PLURAL.convert("lice"), equals("lice")); expect(PLURAL.convert('lice'), equals('lice'));
expect(PLURAL.convert("ox"), equals("oxen")); expect(PLURAL.convert('ox'), equals('oxen'));
expect(PLURAL.convert("ox"), equals("oxen")); expect(PLURAL.convert('ox'), equals('oxen'));
expect(PLURAL.convert("oxen"), equals("oxen")); expect(PLURAL.convert('oxen'), equals('oxen'));
expect(PLURAL.convert("quiz"), equals("quizzes")); expect(PLURAL.convert('quiz'), equals('quizzes'));
}); });
test("handles uncountable nouns", () { test('handles uncountable nouns', () {
uncountableNouns.forEach((noun) { uncountableNouns.forEach((noun) {
expect(PLURAL.convert(noun), equals(noun)); expect(PLURAL.convert(noun), equals(noun));
}); });
@ -56,11 +55,11 @@ void main() {
}); });
}); });
test("handles irregular plural nouns", () { test('handles irregular plural nouns', () {
expect(PLURAL.convert("person"), equals("people")); expect(PLURAL.convert('person'), equals('people'));
expect(PLURAL.convert("Child"), equals("Children")); expect(PLURAL.convert('Child'), equals('Children'));
expect(PLURAL.convert("children"), equals("children")); expect(PLURAL.convert('children'), equals('children'));
expect(PLURAL.convert("man"), equals("men")); expect(PLURAL.convert('man'), equals('men'));
}); });
}); });
} }

View file

@ -1,35 +1,34 @@
library inflection3.plural_verb.test; library inflection3.plural_verb.test;
import 'package:inflection3/inflection3.dart';
import 'package:test/test.dart'; import 'package:test/test.dart';
import '../lib/src/plural_verb.dart';
void main() { void main() {
group("The PluralVerbEncoder", () { group('The PluralVerbEncoder', () {
test("converts verbs from singular to plural", () { test('converts verbs from singular to plural', () {
expect(PLURALVERB.convert(""), equals("")); expect(PLURALVERB.convert(''), equals(''));
expect(PLURALVERB.convert("eats"), equals("eat")); expect(PLURALVERB.convert('eats'), equals('eat'));
expect(PLURALVERB.convert("goes"), equals("go")); expect(PLURALVERB.convert('goes'), equals('go'));
expect(PLURALVERB.convert("boxes"), equals("box")); expect(PLURALVERB.convert('boxes'), equals('box'));
expect(PLURALVERB.convert("pays"), equals("pay")); expect(PLURALVERB.convert('pays'), equals('pay'));
expect(PLURALVERB.convert("rides"), equals("ride")); expect(PLURALVERB.convert('rides'), equals('ride'));
expect(PLURALVERB.convert("writes"), equals("write")); expect(PLURALVERB.convert('writes'), equals('write'));
expect(PLURALVERB.convert("wears"), equals("wear")); expect(PLURALVERB.convert('wears'), equals('wear'));
expect(PLURALVERB.convert("steals"), equals("steal")); expect(PLURALVERB.convert('steals'), equals('steal'));
expect(PLURALVERB.convert("springs"), equals("spring")); expect(PLURALVERB.convert('springs'), equals('spring'));
expect(PLURALVERB.convert("speaks"), equals("speak")); expect(PLURALVERB.convert('speaks'), equals('speak'));
expect(PLURALVERB.convert("sings"), equals("sing")); expect(PLURALVERB.convert('sings'), equals('sing'));
expect(PLURALVERB.convert("buses"), equals("bus")); expect(PLURALVERB.convert('buses'), equals('bus'));
expect(PLURALVERB.convert("knows"), equals("know")); expect(PLURALVERB.convert('knows'), equals('know'));
expect(PLURALVERB.convert("hides"), equals("hide")); expect(PLURALVERB.convert('hides'), equals('hide'));
expect(PLURALVERB.convert("catches"), equals("catch")); expect(PLURALVERB.convert('catches'), equals('catch'));
}); });
test("handles irregular plural verbs", () { test('handles irregular plural verbs', () {
expect(PLURALVERB.convert("am"), equals("are")); expect(PLURALVERB.convert('am'), equals('are'));
expect(PLURALVERB.convert("is"), equals("are")); expect(PLURALVERB.convert('is'), equals('are'));
expect(PLURALVERB.convert("was"), equals("were")); expect(PLURALVERB.convert('was'), equals('were'));
expect(PLURALVERB.convert("has"), equals("have")); expect(PLURALVERB.convert('has'), equals('have'));
}); });
}); });
} }

View file

@ -1,50 +1,49 @@
library inflection3.singular.test; library inflection3.singular.test;
import 'package:inflection3/inflection3.dart';
import 'package:inflection3/src/uncountable_nouns.dart';
import 'package:test/test.dart'; import 'package:test/test.dart';
import '../lib/src/singular.dart';
import '../lib/src/uncountable_nouns.dart';
void main() { void main() {
group("The SingularEncoder", () { group('The SingularEncoder', () {
test("converts nouns from plural to singular", () { test('converts nouns from plural to singular', () {
expect(SINGULAR.convert(""), equals("")); expect(SINGULAR.convert(''), equals(''));
expect(SINGULAR.convert("Houses"), equals("House")); expect(SINGULAR.convert('Houses'), equals('House'));
expect(SINGULAR.convert("houses"), equals("house")); expect(SINGULAR.convert('houses'), equals('house'));
expect(SINGULAR.convert("ultimata"), equals("ultimatum")); expect(SINGULAR.convert('ultimata'), equals('ultimatum'));
expect(SINGULAR.convert("pentia"), equals("pentium")); expect(SINGULAR.convert('pentia'), equals('pentium'));
expect(SINGULAR.convert("analyses"), equals("analysis")); expect(SINGULAR.convert('analyses'), equals('analysis'));
expect(SINGULAR.convert("diagnoses"), equals("diagnosis")); expect(SINGULAR.convert('diagnoses'), equals('diagnosis'));
expect(SINGULAR.convert("Parentheses"), equals("Parenthesis")); expect(SINGULAR.convert('Parentheses'), equals('Parenthesis'));
expect(SINGULAR.convert("lives"), equals("life")); expect(SINGULAR.convert('lives'), equals('life'));
expect(SINGULAR.convert("hives"), equals("hive")); expect(SINGULAR.convert('hives'), equals('hive'));
expect(SINGULAR.convert("tives"), equals("tive")); expect(SINGULAR.convert('tives'), equals('tive'));
expect(SINGULAR.convert("shelves"), equals("shelf")); expect(SINGULAR.convert('shelves'), equals('shelf'));
expect(SINGULAR.convert("qualities"), equals("quality")); expect(SINGULAR.convert('qualities'), equals('quality'));
expect(SINGULAR.convert("series"), equals("series")); expect(SINGULAR.convert('series'), equals('series'));
expect(SINGULAR.convert("movies"), equals("movie")); expect(SINGULAR.convert('movies'), equals('movie'));
expect(SINGULAR.convert("benches"), equals("bench")); expect(SINGULAR.convert('benches'), equals('bench'));
expect(SINGULAR.convert("fishes"), equals("fish")); expect(SINGULAR.convert('fishes'), equals('fish'));
expect(SINGULAR.convert("mice"), equals("mouse")); expect(SINGULAR.convert('mice'), equals('mouse'));
expect(SINGULAR.convert("lice"), equals("louse")); expect(SINGULAR.convert('lice'), equals('louse'));
expect(SINGULAR.convert("buses"), equals("bus")); expect(SINGULAR.convert('buses'), equals('bus'));
expect(SINGULAR.convert("shoes"), equals("shoe")); expect(SINGULAR.convert('shoes'), equals('shoe'));
expect(SINGULAR.convert("testis"), equals("testis")); expect(SINGULAR.convert('testis'), equals('testis'));
expect(SINGULAR.convert("crisis"), equals("crisis")); expect(SINGULAR.convert('crisis'), equals('crisis'));
expect(SINGULAR.convert("axes"), equals("axis")); expect(SINGULAR.convert('axes'), equals('axis'));
expect(SINGULAR.convert("axis"), equals("axis")); expect(SINGULAR.convert('axis'), equals('axis'));
expect(SINGULAR.convert("viri"), equals("virus")); expect(SINGULAR.convert('viri'), equals('virus'));
expect(SINGULAR.convert("octopi"), equals("octopus")); expect(SINGULAR.convert('octopi'), equals('octopus'));
expect(SINGULAR.convert("aliases"), equals("alias")); expect(SINGULAR.convert('aliases'), equals('alias'));
expect(SINGULAR.convert("statuses"), equals("status")); expect(SINGULAR.convert('statuses'), equals('status'));
expect(SINGULAR.convert("vertices"), equals("vertex")); expect(SINGULAR.convert('vertices'), equals('vertex'));
expect(SINGULAR.convert("indices"), equals("index")); expect(SINGULAR.convert('indices'), equals('index'));
expect(SINGULAR.convert("Matrices"), equals("Matrix")); expect(SINGULAR.convert('Matrices'), equals('Matrix'));
expect(SINGULAR.convert("quizzes"), equals("quiz")); expect(SINGULAR.convert('quizzes'), equals('quiz'));
expect(SINGULAR.convert("databases"), equals("database")); expect(SINGULAR.convert('databases'), equals('database'));
}); });
test("handles uncountable nouns", () { test('handles uncountable nouns', () {
uncountableNouns.forEach((noun) { uncountableNouns.forEach((noun) {
expect(SINGULAR.convert(noun), equals(noun)); expect(SINGULAR.convert(noun), equals(noun));
}); });
@ -55,11 +54,11 @@ void main() {
}); });
}); });
test("handles irregular plural nouns", () { test('handles irregular plural nouns', () {
expect(SINGULAR.convert("people"), equals("person")); expect(SINGULAR.convert('people'), equals('person'));
expect(SINGULAR.convert("Children"), equals("Child")); expect(SINGULAR.convert('Children'), equals('Child'));
expect(SINGULAR.convert("child"), equals("child")); expect(SINGULAR.convert('child'), equals('child'));
expect(SINGULAR.convert("men"), equals("man")); expect(SINGULAR.convert('men'), equals('man'));
}); });
}); });
} }

View file

@ -1,34 +1,33 @@
library inflection3.singular_verb.test; library inflection3.singular_verb.test;
import 'package:inflection3/inflection3.dart';
import 'package:test/test.dart'; import 'package:test/test.dart';
import '../lib/src/singular_verb.dart';
void main() { void main() {
group("The SingularVerbEncoder", () { group('The SingularVerbEncoder', () {
test("converts verbs from singular to plural", () { test('converts verbs from singular to plural', () {
expect(SINGULARVERB.convert(""), equals("")); expect(SINGULARVERB.convert(''), equals(''));
expect(SINGULARVERB.convert("eat"), equals("eats")); expect(SINGULARVERB.convert('eat'), equals('eats'));
expect(SINGULARVERB.convert("go"), equals("goes")); expect(SINGULARVERB.convert('go'), equals('goes'));
expect(SINGULARVERB.convert("box"), equals("boxes")); expect(SINGULARVERB.convert('box'), equals('boxes'));
expect(SINGULARVERB.convert("pay"), equals("pays")); expect(SINGULARVERB.convert('pay'), equals('pays'));
expect(SINGULARVERB.convert("ride"), equals("rides")); expect(SINGULARVERB.convert('ride'), equals('rides'));
expect(SINGULARVERB.convert("write"), equals("writes")); expect(SINGULARVERB.convert('write'), equals('writes'));
expect(SINGULARVERB.convert("wear"), equals("wears")); expect(SINGULARVERB.convert('wear'), equals('wears'));
expect(SINGULARVERB.convert("steal"), equals("steals")); expect(SINGULARVERB.convert('steal'), equals('steals'));
expect(SINGULARVERB.convert("spring"), equals("springs")); expect(SINGULARVERB.convert('spring'), equals('springs'));
expect(SINGULARVERB.convert("speak"), equals("speaks")); expect(SINGULARVERB.convert('speak'), equals('speaks'));
expect(SINGULARVERB.convert("sing"), equals("sings")); expect(SINGULARVERB.convert('sing'), equals('sings'));
expect(SINGULARVERB.convert("bus"), equals("buses")); expect(SINGULARVERB.convert('bus'), equals('buses'));
expect(SINGULARVERB.convert("know"), equals("knows")); expect(SINGULARVERB.convert('know'), equals('knows'));
expect(SINGULARVERB.convert("hide"), equals("hides")); expect(SINGULARVERB.convert('hide'), equals('hides'));
expect(SINGULARVERB.convert("catch"), equals("catches")); expect(SINGULARVERB.convert('catch'), equals('catches'));
}); });
test("handles irregular plural verbs", () { test('handles irregular plural verbs', () {
expect(SINGULARVERB.convert("are"), equals("is")); expect(SINGULARVERB.convert('are'), equals('is'));
expect(SINGULARVERB.convert("were"), equals("was")); expect(SINGULARVERB.convert('were'), equals('was'));
expect(SINGULARVERB.convert("have"), equals("has")); expect(SINGULARVERB.convert('have'), equals('has'));
}); });
}); });
} }

View file

@ -1,19 +1,18 @@
library inflection3.snake_case.test; library inflection3.snake_case.test;
import 'package:inflection3/inflection3.dart';
import 'package:test/test.dart'; import 'package:test/test.dart';
import '../lib/src/snake_case.dart';
void main() { void main() {
group("The SnakeCaseEncoder", () { group('The SnakeCaseEncoder', () {
test("converts phrases to 'snake_case'", () { test('converts phrases to "snake_case"', () {
expect(SNAKE_CASE.convert(''), equals('')); expect(SNAKE_CASE.convert(''), equals(''));
expect(SNAKE_CASE.convert("CamelCaseName"), equals("camel_case_name")); expect(SNAKE_CASE.convert('CamelCaseName'), equals('camel_case_name'));
expect(SNAKE_CASE.convert("propertyName"), equals("property_name")); expect(SNAKE_CASE.convert('propertyName'), equals('property_name'));
expect(SNAKE_CASE.convert("property"), equals("property")); expect(SNAKE_CASE.convert('property'), equals('property'));
expect(SNAKE_CASE.convert("lisp-case"), equals("lisp_case")); expect(SNAKE_CASE.convert('lisp-case'), equals('lisp_case'));
expect(SNAKE_CASE.convert("This is a nice article"), expect(SNAKE_CASE.convert('This is a nice article'),
equals("this_is_a_nice_article")); equals('this_is_a_nice_article'));
}); });
}); });
} }

View file

@ -1,19 +1,18 @@
library inflection3.spinal_case.test; library inflection3.spinal_case.test;
import 'package:inflection3/inflection3.dart';
import 'package:test/test.dart'; import 'package:test/test.dart';
import '../lib/src/spinal_case.dart';
void main() { void main() {
group("The SpinalCaseEncoder", () { group('The SpinalCaseEncoder', () {
test("converts phrases to 'spinal-case'", () { test('converts phrases to "spinal-case"', () {
expect(SPINAL_CASE.convert(''), equals('')); expect(SPINAL_CASE.convert(''), equals(''));
expect(SPINAL_CASE.convert("CamelCaseName"), equals("camel-case-name")); expect(SPINAL_CASE.convert('CamelCaseName'), equals('camel-case-name'));
expect(SPINAL_CASE.convert("propertyName"), equals("property-name")); expect(SPINAL_CASE.convert('propertyName'), equals('property-name'));
expect(SPINAL_CASE.convert("property"), equals("property")); expect(SPINAL_CASE.convert('property'), equals('property'));
expect(SPINAL_CASE.convert("snake_case"), equals("snake-case")); expect(SPINAL_CASE.convert('snake_case'), equals('snake-case'));
expect(SPINAL_CASE.convert("This is a nice article"), expect(SPINAL_CASE.convert('This is a nice article'),
equals("this-is-a-nice-article")); equals('this-is-a-nice-article'));
}); });
}); });
} }