This commit is contained in:
mockturtl
2015-05-09 20:03:34 -04:00
parent e5bfd935c9
commit c4f30559d3
4 changed files with 41 additions and 7 deletions

View File

@ -16,16 +16,36 @@ void main() {
test('it skips empty lines', subj.parse_empty);
test('it ignores duplicate keys', subj.parse_dup);
test('it substitutes known variables into other values', subj.parse_subs);
test('it detects unquoted values', subj.surroundingQuote_none);
test('it detects double-quoted values', subj.surroundingQuote_double);
test('it detects single-quoted values', subj.surroundingQuote_single);
test('it performs variable substitution', subj.interpolate);
test('it skips undefined variables', subj.interpolate_missing);
test('it handles explicitly null values in env', subj.interpolate_missing2);
});
}
const _psr = const Parser();
class ParserTest {
void interpolate() {
var out = _psr.interpolate(r'a$foo$baz', {'foo': 'bar', 'baz': 'qux'});
expect(out, equals('abarqux'));
}
void interpolate_missing() {
var out = _psr.interpolate(r'a$foo$baz', {});
expect(out, equals('a'));
}
void interpolate_missing2() {
var out = _psr.interpolate(r'a$foo$baz', {'foo': null});
expect(out, equals('a'));
}
void surroundingQuote_none() {
var out = _psr.surroundingQuote('no quotes here!');
expect(out, isEmpty);
@ -93,4 +113,9 @@ class ParserTest {
var out = _psr.parse(['foo=bar', 'foo=baz']);
expect(out, equals({'foo': 'bar'}));
}
void parse_subs() {
var out = _psr.parse(['foo=bar', r'baz=super$foo']);
expect(out, equals({'foo': 'bar', 'baz': 'superbar'}));
}
}