OLD | NEW |
(Empty) | |
| 1 dart_library.library('language/reg_exp_test', null, /* Imports */[ |
| 2 'dart_sdk', |
| 3 'expect' |
| 4 ], function load__reg_exp_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 reg_exp_test = Object.create(null); |
| 12 let JSArrayOfString = () => (JSArrayOfString = dart.constFn(_interceptors.JSAr
ray$(core.String)))(); |
| 13 let IterableOfMatch = () => (IterableOfMatch = dart.constFn(core.Iterable$(cor
e.Match)))(); |
| 14 let MatchToString = () => (MatchToString = dart.constFn(dart.definiteFunctionT
ype(core.String, [core.Match])))(); |
| 15 let VoidToIterableOfMatch = () => (VoidToIterableOfMatch = dart.constFn(dart.d
efiniteFunctionType(IterableOfMatch(), [])))(); |
| 16 let VoidToMatch = () => (VoidToMatch = dart.constFn(dart.definiteFunctionType(
core.Match, [])))(); |
| 17 let VoidTovoid = () => (VoidTovoid = dart.constFn(dart.definiteFunctionType(da
rt.void, [])))(); |
| 18 reg_exp_test.main = function() { |
| 19 let exp = core.RegExp.new("(\\w+)"); |
| 20 let str = "Parse my string"; |
| 21 let matches = exp.allMatches(str)[dartx.toList](); |
| 22 expect$.Expect.equals(3, matches[dartx.length]); |
| 23 expect$.Expect.equals("Parse", matches[dartx.get](0).group(0)); |
| 24 expect$.Expect.equals("my", matches[dartx.get](1).group(0)); |
| 25 expect$.Expect.equals("string", matches[dartx.get](2).group(0)); |
| 26 exp = core.RegExp.new("a?"); |
| 27 str = "babba"; |
| 28 expect$.Expect.listEquals(JSArrayOfString().of(["", "a", "", "", "a", ""]),
exp.allMatches(str)[dartx.map](core.String)(dart.fn(x => x.get(0), MatchToString
()))[dartx.toList]()); |
| 29 exp = core.RegExp.new("as{2}"); |
| 30 str = "assassin"; |
| 31 expect$.Expect.equals(2, exp.allMatches(str)[dartx.length]); |
| 32 expect$.Expect.equals(2, exp.allMatches(str, 0)[dartx.length]); |
| 33 expect$.Expect.equals(1, exp.allMatches(str, 1)[dartx.length]); |
| 34 expect$.Expect.equals(0, exp.allMatches(str, 4)[dartx.length]); |
| 35 expect$.Expect.equals(0, exp.allMatches(str, str[dartx.length])[dartx.length
]); |
| 36 expect$.Expect.throws(dart.fn(() => exp.allMatches(str, -1), VoidToIterableO
fMatch())); |
| 37 expect$.Expect.throws(dart.fn(() => exp.allMatches(str, dart.notNull(str[dar
tx.length]) + 1), VoidToIterableOfMatch())); |
| 38 exp = core.RegExp.new(".*"); |
| 39 expect$.Expect.equals("", exp.allMatches(str, str[dartx.length])[dartx.singl
e].get(0)); |
| 40 exp = core.RegExp.new("^ass"); |
| 41 expect$.Expect.equals(1, exp.allMatches(str, 0)[dartx.length]); |
| 42 expect$.Expect.equals(0, exp.allMatches(str, 3)[dartx.length]); |
| 43 exp = core.RegExp.new("^", {multiLine: true}); |
| 44 str = "foo\nbar\nbaz"; |
| 45 expect$.Expect.equals(" foo\n bar\n baz", str[dartx.replaceAll](exp, " ")); |
| 46 exp = core.RegExp.new("(\\w+)"); |
| 47 expect$.Expect.isNull(exp.matchAsPrefix(" xyz ab")); |
| 48 expect$.Expect.isNull(exp.matchAsPrefix(" xyz ab", 0)); |
| 49 let m = exp.matchAsPrefix(" xyz ab", 1); |
| 50 expect$.Expect.equals("xyz", m.get(0)); |
| 51 expect$.Expect.equals("xyz", m.get(1)); |
| 52 expect$.Expect.equals(1, m.groupCount); |
| 53 m = exp.matchAsPrefix(" xyz ab", 2); |
| 54 expect$.Expect.equals("yz", m.get(0)); |
| 55 expect$.Expect.equals("yz", m.get(1)); |
| 56 expect$.Expect.equals(1, m.groupCount); |
| 57 m = exp.matchAsPrefix(" xyz ab", 3); |
| 58 expect$.Expect.equals("z", m.get(0)); |
| 59 expect$.Expect.equals("z", m.get(1)); |
| 60 expect$.Expect.equals(1, m.groupCount); |
| 61 expect$.Expect.isNull(exp.matchAsPrefix(" xyz ab", 4)); |
| 62 m = exp.matchAsPrefix(" xyz ab", 5); |
| 63 expect$.Expect.equals("ab", m.get(0)); |
| 64 expect$.Expect.equals("ab", m.get(1)); |
| 65 expect$.Expect.equals(1, m.groupCount); |
| 66 m = exp.matchAsPrefix(" xyz ab", 6); |
| 67 expect$.Expect.equals("b", m.get(0)); |
| 68 expect$.Expect.equals("b", m.get(1)); |
| 69 expect$.Expect.equals(1, m.groupCount); |
| 70 expect$.Expect.isNull(exp.matchAsPrefix(" xyz ab", 7)); |
| 71 expect$.Expect.throws(dart.fn(() => exp.matchAsPrefix(" xyz ab", -1), VoidTo
Match())); |
| 72 expect$.Expect.throws(dart.fn(() => exp.matchAsPrefix(" xyz ab", 8), VoidToM
atch())); |
| 73 }; |
| 74 dart.fn(reg_exp_test.main, VoidTovoid()); |
| 75 // Exports: |
| 76 exports.reg_exp_test = reg_exp_test; |
| 77 }); |
OLD | NEW |