OLD | NEW |
(Empty) | |
| 1 dart_library.library('corelib/regexp/ecma-regex-examples_test', null, /* Imports
*/[ |
| 2 'dart_sdk', |
| 3 'expect' |
| 4 ], function load__ecma$45regex$45examples_test(exports, dart_sdk, expect) { |
| 5 'use strict'; |
| 6 const core = dart_sdk.core; |
| 7 const _interceptors = dart_sdk._interceptors; |
| 8 const dart = dart_sdk.dart; |
| 9 const dartx = dart_sdk.dartx; |
| 10 const expect$ = expect.expect; |
| 11 const ecma$45regex$45examples_test = Object.create(null); |
| 12 const v8_regexp_utils = Object.create(null); |
| 13 let JSArrayOfString = () => (JSArrayOfString = dart.constFn(_interceptors.JSAr
ray$(core.String)))(); |
| 14 let VoidTovoid = () => (VoidTovoid = dart.constFn(dart.functionType(dart.void,
[])))(); |
| 15 let ListOfString = () => (ListOfString = dart.constFn(core.List$(core.String))
)(); |
| 16 let MatchToString = () => (MatchToString = dart.constFn(dart.definiteFunctionT
ype(core.String, [core.Match])))(); |
| 17 let VoidTovoid$ = () => (VoidTovoid$ = dart.constFn(dart.definiteFunctionType(
dart.void, [])))(); |
| 18 let dynamicAnddynamic__Tovoid = () => (dynamicAnddynamic__Tovoid = dart.constF
n(dart.definiteFunctionType(dart.void, [dart.dynamic, dart.dynamic], [core.Strin
g])))(); |
| 19 let dynamic__Tovoid = () => (dynamic__Tovoid = dart.constFn(dart.definiteFunct
ionType(dart.void, [dart.dynamic], [core.String])))(); |
| 20 let dynamic__Tovoid$ = () => (dynamic__Tovoid$ = dart.constFn(dart.definiteFun
ctionType(dart.void, [dart.dynamic], [core.num])))(); |
| 21 let dynamicAnddynamicAndnumTovoid = () => (dynamicAnddynamicAndnumTovoid = dar
t.constFn(dart.definiteFunctionType(dart.void, [dart.dynamic, dart.dynamic, core
.num])))(); |
| 22 let dynamicTovoid = () => (dynamicTovoid = dart.constFn(dart.definiteFunctionT
ype(dart.void, [dart.dynamic])))(); |
| 23 let StringAndRegExpToMatch = () => (StringAndRegExpToMatch = dart.constFn(dart
.definiteFunctionType(core.Match, [core.String, core.RegExp])))(); |
| 24 let StringAndRegExpToListOfString = () => (StringAndRegExpToListOfString = dar
t.constFn(dart.definiteFunctionType(ListOfString(), [core.String, core.RegExp]))
)(); |
| 25 ecma$45regex$45examples_test.main = function() { |
| 26 v8_regexp_utils.description("This page tests the regex examples from the ECM
A-262 specification."); |
| 27 let regex01 = core.RegExp.new("a|ab"); |
| 28 v8_regexp_utils.shouldBe(regex01.firstMatch("abc"), JSArrayOfString().of(["a
"])); |
| 29 let regex02 = core.RegExp.new("((a)|(ab))((c)|(bc))"); |
| 30 v8_regexp_utils.shouldBe(regex02.firstMatch("abc"), JSArrayOfString().of(["a
bc", "a", "a", null, "bc", null, "bc"])); |
| 31 let regex03 = core.RegExp.new("a[a-z]{2,4}"); |
| 32 v8_regexp_utils.shouldBe(regex03.firstMatch("abcdefghi"), JSArrayOfString().
of(["abcde"])); |
| 33 let regex04 = core.RegExp.new("a[a-z]{2,4}?"); |
| 34 v8_regexp_utils.shouldBe(regex04.firstMatch("abcdefghi"), JSArrayOfString().
of(["abc"])); |
| 35 let regex05 = core.RegExp.new("(aa|aabaac|ba|b|c)*"); |
| 36 v8_regexp_utils.shouldBe(regex05.firstMatch("aabaac"), JSArrayOfString().of(
["aaba", "ba"])); |
| 37 let regex06 = core.RegExp.new("^(a+)\\1*,\\1+$"); |
| 38 expect$.Expect.equals("aaaaaaaaaa,aaaaaaaaaaaaaaa"[dartx.replaceAllMapped](r
egex06, dart.fn(m => m.group(1), MatchToString())), "aaaaa"); |
| 39 let regex07 = core.RegExp.new("(z)((a+)?(b+)?(c))*"); |
| 40 v8_regexp_utils.shouldBe(regex07.firstMatch("zaacbbbcac"), JSArrayOfString()
.of(["zaacbbbcac", "z", "ac", "a", null, "c"])); |
| 41 let regex08 = core.RegExp.new("(a*)*"); |
| 42 v8_regexp_utils.shouldBe(regex08.firstMatch("b"), JSArrayOfString().of(["",
null])); |
| 43 let regex09 = core.RegExp.new("(a*)b\\1+"); |
| 44 v8_regexp_utils.shouldBe(regex09.firstMatch("baaaac"), JSArrayOfString().of(
["b", ""])); |
| 45 let regex10 = core.RegExp.new("(?=(a+))"); |
| 46 v8_regexp_utils.shouldBe(regex10.firstMatch("baaabac"), JSArrayOfString().of
(["", "aaa"])); |
| 47 let regex11 = core.RegExp.new("(?=(a+))a*b\\1"); |
| 48 v8_regexp_utils.shouldBe(regex11.firstMatch("baaabac"), JSArrayOfString().of
(["aba", "a"])); |
| 49 let regex12 = core.RegExp.new("(.*?)a(?!(a+)b\\2c)\\2(.*)"); |
| 50 v8_regexp_utils.shouldBe(regex12.firstMatch("baaabaac"), JSArrayOfString().o
f(["baaabaac", "ba", null, "abaac"])); |
| 51 }; |
| 52 dart.fn(ecma$45regex$45examples_test.main, VoidTovoid$()); |
| 53 v8_regexp_utils.assertEquals = function(actual, expected, message) { |
| 54 if (message === void 0) message = null; |
| 55 expect$.Expect.equals(actual, expected, message); |
| 56 }; |
| 57 dart.fn(v8_regexp_utils.assertEquals, dynamicAnddynamic__Tovoid()); |
| 58 v8_regexp_utils.assertTrue = function(actual, message) { |
| 59 if (message === void 0) message = null; |
| 60 expect$.Expect.isTrue(actual, message); |
| 61 }; |
| 62 dart.fn(v8_regexp_utils.assertTrue, dynamic__Tovoid()); |
| 63 v8_regexp_utils.assertFalse = function(actual, message) { |
| 64 if (message === void 0) message = null; |
| 65 expect$.Expect.isFalse(actual, message); |
| 66 }; |
| 67 dart.fn(v8_regexp_utils.assertFalse, dynamic__Tovoid()); |
| 68 v8_regexp_utils.assertThrows = function(fn, testid) { |
| 69 if (testid === void 0) testid = null; |
| 70 expect$.Expect.throws(VoidTovoid()._check(fn), null, dart.str`Test ${testid}
`); |
| 71 }; |
| 72 dart.fn(v8_regexp_utils.assertThrows, dynamic__Tovoid$()); |
| 73 v8_regexp_utils.assertNull = function(actual, testid) { |
| 74 if (testid === void 0) testid = null; |
| 75 expect$.Expect.isNull(actual, dart.str`Test ${testid}`); |
| 76 }; |
| 77 dart.fn(v8_regexp_utils.assertNull, dynamic__Tovoid$()); |
| 78 v8_regexp_utils.assertToStringEquals = function(str, match, testid) { |
| 79 let actual = []; |
| 80 for (let i = 0; i <= dart.notNull(core.num._check(dart.dload(match, 'groupCo
unt'))); i++) { |
| 81 let g = dart.dsend(match, 'group', i); |
| 82 actual[dartx.add](g == null ? "" : g); |
| 83 } |
| 84 expect$.Expect.equals(str, actual[dartx.join](","), dart.str`Test ${testid}`
); |
| 85 }; |
| 86 dart.fn(v8_regexp_utils.assertToStringEquals, dynamicAnddynamicAndnumTovoid())
; |
| 87 v8_regexp_utils.shouldBeTrue = function(actual) { |
| 88 expect$.Expect.isTrue(actual); |
| 89 }; |
| 90 dart.fn(v8_regexp_utils.shouldBeTrue, dynamicTovoid()); |
| 91 v8_regexp_utils.shouldBeFalse = function(actual) { |
| 92 expect$.Expect.isFalse(actual); |
| 93 }; |
| 94 dart.fn(v8_regexp_utils.shouldBeFalse, dynamicTovoid()); |
| 95 v8_regexp_utils.shouldBeNull = function(actual) { |
| 96 expect$.Expect.isNull(actual); |
| 97 }; |
| 98 dart.fn(v8_regexp_utils.shouldBeNull, dynamicTovoid()); |
| 99 v8_regexp_utils.shouldBe = function(actual, expected, message) { |
| 100 if (message === void 0) message = null; |
| 101 if (expected == null) { |
| 102 expect$.Expect.isNull(actual, message); |
| 103 } else { |
| 104 expect$.Expect.equals(dart.dload(expected, 'length'), dart.dsend(dart.dloa
d(actual, 'groupCount'), '+', 1)); |
| 105 for (let i = 0; i <= dart.notNull(core.num._check(dart.dload(actual, 'grou
pCount'))); i++) { |
| 106 expect$.Expect.equals(dart.dindex(expected, i), dart.dsend(actual, 'grou
p', i), message); |
| 107 } |
| 108 } |
| 109 }; |
| 110 dart.fn(v8_regexp_utils.shouldBe, dynamicAnddynamic__Tovoid()); |
| 111 v8_regexp_utils.firstMatch = function(str, pattern) { |
| 112 return pattern.firstMatch(str); |
| 113 }; |
| 114 dart.fn(v8_regexp_utils.firstMatch, StringAndRegExpToMatch()); |
| 115 v8_regexp_utils.allStringMatches = function(str, pattern) { |
| 116 return pattern.allMatches(str)[dartx.map](core.String)(dart.fn(m => m.group(
0), MatchToString()))[dartx.toList](); |
| 117 }; |
| 118 dart.fn(v8_regexp_utils.allStringMatches, StringAndRegExpToListOfString()); |
| 119 v8_regexp_utils.description = function(str) { |
| 120 }; |
| 121 dart.fn(v8_regexp_utils.description, dynamicTovoid()); |
| 122 // Exports: |
| 123 exports.ecma$45regex$45examples_test = ecma$45regex$45examples_test; |
| 124 exports.v8_regexp_utils = v8_regexp_utils; |
| 125 }); |
OLD | NEW |