OLD | NEW |
(Empty) | |
| 1 dart_library.library('corelib/string_pattern_test', null, /* Imports */[ |
| 2 'dart_sdk', |
| 3 'expect' |
| 4 ], function load__string_pattern_test(exports, dart_sdk, expect) { |
| 5 'use strict'; |
| 6 const core = dart_sdk.core; |
| 7 const dart = dart_sdk.dart; |
| 8 const dartx = dart_sdk.dartx; |
| 9 const expect$ = expect.expect; |
| 10 const string_pattern_test = Object.create(null); |
| 11 let IterableOfMatch = () => (IterableOfMatch = dart.constFn(core.Iterable$(cor
e.Match)))(); |
| 12 let VoidTodynamic = () => (VoidTodynamic = dart.constFn(dart.definiteFunctionT
ype(dart.dynamic, [])))(); |
| 13 let VoidToMatch = () => (VoidToMatch = dart.constFn(dart.definiteFunctionType(
core.Match, [])))(); |
| 14 let VoidToIterableOfMatch = () => (VoidToIterableOfMatch = dart.constFn(dart.d
efiniteFunctionType(IterableOfMatch(), [])))(); |
| 15 string_pattern_test.str = "this is a string with hello here and hello there"; |
| 16 string_pattern_test.main = function() { |
| 17 string_pattern_test.testNoMatch(); |
| 18 string_pattern_test.testOneMatch(); |
| 19 string_pattern_test.testTwoMatches(); |
| 20 string_pattern_test.testEmptyPattern(); |
| 21 string_pattern_test.testEmptyString(); |
| 22 string_pattern_test.testEmptyPatternAndString(); |
| 23 string_pattern_test.testMatchAsPrefix(); |
| 24 string_pattern_test.testAllMatchesStart(); |
| 25 }; |
| 26 dart.fn(string_pattern_test.main, VoidTodynamic()); |
| 27 string_pattern_test.testNoMatch = function() { |
| 28 let helloPattern = "with (hello)"; |
| 29 let matches = helloPattern[dartx.allMatches](string_pattern_test.str); |
| 30 expect$.Expect.isFalse(matches[dartx.iterator].moveNext()); |
| 31 }; |
| 32 dart.fn(string_pattern_test.testNoMatch, VoidTodynamic()); |
| 33 string_pattern_test.testOneMatch = function() { |
| 34 let helloPattern = "with hello"; |
| 35 let matches = helloPattern[dartx.allMatches](string_pattern_test.str); |
| 36 let iterator = matches[dartx.iterator]; |
| 37 expect$.Expect.isTrue(iterator.moveNext()); |
| 38 let match = iterator.current; |
| 39 expect$.Expect.isFalse(iterator.moveNext()); |
| 40 expect$.Expect.equals(string_pattern_test.str[dartx.indexOf]('with', 0), mat
ch.start); |
| 41 expect$.Expect.equals(dart.notNull(string_pattern_test.str[dartx.indexOf]('w
ith', 0)) + dart.notNull(helloPattern[dartx.length]), match.end); |
| 42 expect$.Expect.equals(helloPattern, match.pattern); |
| 43 expect$.Expect.equals(string_pattern_test.str, match.input); |
| 44 expect$.Expect.equals(helloPattern, match.get(0)); |
| 45 expect$.Expect.equals(0, match.groupCount); |
| 46 }; |
| 47 dart.fn(string_pattern_test.testOneMatch, VoidTodynamic()); |
| 48 string_pattern_test.testTwoMatches = function() { |
| 49 let helloPattern = "hello"; |
| 50 let matches = helloPattern[dartx.allMatches](string_pattern_test.str); |
| 51 let count = 0; |
| 52 let start = 0; |
| 53 for (let match of matches) { |
| 54 count++; |
| 55 expect$.Expect.equals(string_pattern_test.str[dartx.indexOf]('hello', star
t), match.start); |
| 56 expect$.Expect.equals(dart.notNull(string_pattern_test.str[dartx.indexOf](
'hello', start)) + dart.notNull(helloPattern[dartx.length]), match.end); |
| 57 expect$.Expect.equals(helloPattern, match.pattern); |
| 58 expect$.Expect.equals(string_pattern_test.str, match.input); |
| 59 expect$.Expect.equals(helloPattern, match.get(0)); |
| 60 expect$.Expect.equals(0, match.groupCount); |
| 61 start = match.end; |
| 62 } |
| 63 expect$.Expect.equals(2, count); |
| 64 }; |
| 65 dart.fn(string_pattern_test.testTwoMatches, VoidTodynamic()); |
| 66 string_pattern_test.testEmptyPattern = function() { |
| 67 let pattern = ""; |
| 68 let matches = pattern[dartx.allMatches](string_pattern_test.str); |
| 69 expect$.Expect.isTrue(matches[dartx.iterator].moveNext()); |
| 70 }; |
| 71 dart.fn(string_pattern_test.testEmptyPattern, VoidTodynamic()); |
| 72 string_pattern_test.testEmptyString = function() { |
| 73 let pattern = "foo"; |
| 74 let str = ""; |
| 75 let matches = pattern[dartx.allMatches](str); |
| 76 expect$.Expect.isFalse(matches[dartx.iterator].moveNext()); |
| 77 }; |
| 78 dart.fn(string_pattern_test.testEmptyString, VoidTodynamic()); |
| 79 string_pattern_test.testEmptyPatternAndString = function() { |
| 80 let pattern = ""; |
| 81 let str = ""; |
| 82 let matches = pattern[dartx.allMatches](str); |
| 83 expect$.Expect.isTrue(matches[dartx.iterator].moveNext()); |
| 84 }; |
| 85 dart.fn(string_pattern_test.testEmptyPatternAndString, VoidTodynamic()); |
| 86 string_pattern_test.testMatchAsPrefix = function() { |
| 87 let pattern = "an"; |
| 88 let str = "banana"; |
| 89 expect$.Expect.isNull(pattern[dartx.matchAsPrefix](str)); |
| 90 expect$.Expect.isNull(pattern[dartx.matchAsPrefix](str, 0)); |
| 91 let m = pattern[dartx.matchAsPrefix](str, 1); |
| 92 expect$.Expect.equals("an", m.get(0)); |
| 93 expect$.Expect.equals(1, m.start); |
| 94 expect$.Expect.isNull(pattern[dartx.matchAsPrefix](str, 2)); |
| 95 m = pattern[dartx.matchAsPrefix](str, 3); |
| 96 expect$.Expect.equals("an", m.get(0)); |
| 97 expect$.Expect.equals(3, m.start); |
| 98 expect$.Expect.isNull(pattern[dartx.matchAsPrefix](str, 4)); |
| 99 expect$.Expect.isNull(pattern[dartx.matchAsPrefix](str, 5)); |
| 100 expect$.Expect.isNull(pattern[dartx.matchAsPrefix](str, 6)); |
| 101 expect$.Expect.throws(dart.fn(() => pattern[dartx.matchAsPrefix](str, -1), V
oidToMatch())); |
| 102 expect$.Expect.throws(dart.fn(() => pattern[dartx.matchAsPrefix](str, 7), Vo
idToMatch())); |
| 103 }; |
| 104 dart.fn(string_pattern_test.testMatchAsPrefix, VoidTodynamic()); |
| 105 string_pattern_test.testAllMatchesStart = function() { |
| 106 let p = "ass"; |
| 107 let s = "assassin"; |
| 108 expect$.Expect.equals(2, p[dartx.allMatches](s)[dartx.length]); |
| 109 expect$.Expect.equals(2, p[dartx.allMatches](s, 0)[dartx.length]); |
| 110 expect$.Expect.equals(1, p[dartx.allMatches](s, 1)[dartx.length]); |
| 111 expect$.Expect.equals(0, p[dartx.allMatches](s, 4)[dartx.length]); |
| 112 expect$.Expect.equals(0, p[dartx.allMatches](s, s[dartx.length])[dartx.lengt
h]); |
| 113 expect$.Expect.throws(dart.fn(() => p[dartx.allMatches](s, -1), VoidToIterab
leOfMatch())); |
| 114 expect$.Expect.throws(dart.fn(() => p[dartx.allMatches](s, dart.notNull(s[da
rtx.length]) + 1), VoidToIterableOfMatch())); |
| 115 }; |
| 116 dart.fn(string_pattern_test.testAllMatchesStart, VoidTodynamic()); |
| 117 // Exports: |
| 118 exports.string_pattern_test = string_pattern_test; |
| 119 }); |
OLD | NEW |