Skip to content

Commit

Permalink
Added two string specific matchers
Browse files Browse the repository at this point in the history
  • Loading branch information
Robert Beeger committed Mar 28, 2012
1 parent 2a1a9ef commit 146181e
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/dahlia.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#source('matcher/matcher_base.dart');
#source('matcher/general.dart');
#source('matcher/string.dart');

#source('structure/expectation.dart');
#source('structure/block.dart');
Expand Down
28 changes: 28 additions & 0 deletions src/matcher/string.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
StartWithMatcher startWith(var expected) => new StartWithMatcher(expected);
ContainSubstringMatcher containSubstring(var expected) => new ContainSubstringMatcher(expected);

class StartWithMatcher implements Matcher {
final expected;
const StartWithMatcher(this.expected);

matches(var actual) {
return (actual.startsWith(expected));
}

String describeExpectation(var actual) {
return 'actual "$actual" to start with the expected "$expected"';
}
}

class ContainSubstringMatcher implements Matcher {
final expected;
const ContainSubstringMatcher(this.expected);

matches(var actual) {
return (actual.contains(expected));
}

String describeExpectation(var actual) {
return 'actual "$actual" to contain the expected "$expected"';
}
}
11 changes: 11 additions & 0 deletions tests/suites/string_matchers_tests.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
stringMatchersTests() {
describe('startWith matcher', () {
it('should succeed if the actual string starts with the expected string', () => expect('hallo').to(startWith('ha')));
it('should fail if the actual string does not start with the expected string', () => expect('hallo').to(not(startWith('test'))));
});
describe('containSubstring matcher', () {
it('should succeed if the actual string starts with the expected string', () => expect('hallo').to(containSubstring('ha')));
it('should succeed if the actual string contains the expected string', () => expect('hallo').to(containSubstring('al')));
it('should fail if the actual string does not contain the expected string', () => expect('hallo').to(not(containSubstring('test'))));
});
}
2 changes: 2 additions & 0 deletions tests/test_suites.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@
#import('../src/dahlia.dart');

#source('suites/general_matcher_tests.dart');
#source('suites/string_matchers_tests.dart');
#source('suites/block_tests.dart');
#source('suites/expectation_tests.dart');
#source('suites/runner_tests.dart');

testSuites() {
generalMatcherTests();
stringMatchersTests();
blockTests();
expectationTests();
runnerTests();
Expand Down

0 comments on commit 146181e

Please sign in to comment.