Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(52)

Side by Side Diff: tests/corelib_2/regexp/global_test.dart

Issue 2989863002: Migrated test block 19 to Dart 2.0. (Closed)
Patch Set: Created 3 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. All rights reserved. 1 // Copyright (c) 2014, the Dart project authors. All rights reserved.
2 // Copyright 2012 the V8 project authors. All rights reserved. 2 // Copyright 2012 the V8 project authors. All rights reserved.
3 // Redistribution and use in source and binary forms, with or without 3 // Redistribution and use in source and binary forms, with or without
4 // modification, are permitted provided that the following conditions are 4 // modification, are permitted provided that the following conditions are
5 // met: 5 // met:
6 // 6 //
7 // * Redistributions of source code must retain the above copyright 7 // * Redistributions of source code must retain the above copyright
8 // notice, this list of conditions and the following disclaimer. 8 // notice, this list of conditions and the following disclaimer.
9 // * Redistributions in binary form must reproduce the above 9 // * Redistributions in binary form must reproduce the above
10 // copyright notice, this list of conditions and the following 10 // copyright notice, this list of conditions and the following
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 if (m.group(2) != null) return "+"; 53 if (m.group(2) != null) return "+";
54 if (m.group(3) != null) return "="; 54 if (m.group(3) != null) return "=";
55 }); 55 });
56 assertEquals("= -. +, or + -. There is - =.", str); 56 assertEquals("= -. +, or + -. There is - =.", str);
57 57
58 // Test multiple alternate captures. 58 // Test multiple alternate captures.
59 str = "FOUR LEGS GOOD, TWO LEGS BAD!"; 59 str = "FOUR LEGS GOOD, TWO LEGS BAD!";
60 str = str.replaceAllMapped(new RegExp(r"(FOUR|TWO) LEGS (GOOD|BAD)"), (m) { 60 str = str.replaceAllMapped(new RegExp(r"(FOUR|TWO) LEGS (GOOD|BAD)"), (m) {
61 if (m.group(1) == "FOUR") assertTrue(m.group(2) == "GOOD"); 61 if (m.group(1) == "FOUR") assertTrue(m.group(2) == "GOOD");
62 if (m.group(1) == "TWO") assertTrue(m.group(2) == "BAD"); 62 if (m.group(1) == "TWO") assertTrue(m.group(2) == "BAD");
63 return m.group(0).length - 10; 63 return (m.group(0).length - 10).toString();
64 }); 64 });
65 assertEquals("4, 2!", str); 65 assertEquals("4, 2!", str);
66 66
67 // The same tests with UC16. 67 // The same tests with UC16.
68 68
69 //Test that an optional capture is cleared between two matches. 69 //Test that an optional capture is cleared between two matches.
70 str = "AB\u1234 \u1234"; 70 str = "AB\u1234 \u1234";
71 str = str.replaceAll(new RegExp(r"(\w)?\u1234"), "c"); 71 str = str.replaceAll(new RegExp(r"(\w)?\u1234"), "c");
72 assertEquals("Ac c", str); 72 assertEquals("Ac c", str);
73 73
(...skipping 15 matching lines...) Expand all
89 if (m.group(2) != null) return "+"; 89 if (m.group(2) != null) return "+";
90 if (m.group(3) != null) return "="; 90 if (m.group(3) != null) return "=";
91 }); 91 });
92 assertEquals("= -. +, or + -. There is - =.", str); 92 assertEquals("= -. +, or + -. There is - =.", str);
93 93
94 // Test multiple alternate captures. 94 // Test multiple alternate captures.
95 str = "FOUR \u817f GOOD, TWO \u817f BAD!"; 95 str = "FOUR \u817f GOOD, TWO \u817f BAD!";
96 str = str.replaceAllMapped(new RegExp(r"(FOUR|TWO) \u817f (GOOD|BAD)"), (m) { 96 str = str.replaceAllMapped(new RegExp(r"(FOUR|TWO) \u817f (GOOD|BAD)"), (m) {
97 if (m.group(1) == "FOUR") assertTrue(m.group(2) == "GOOD"); 97 if (m.group(1) == "FOUR") assertTrue(m.group(2) == "GOOD");
98 if (m.group(1) == "TWO") assertTrue(m.group(2) == "BAD"); 98 if (m.group(1) == "TWO") assertTrue(m.group(2) == "BAD");
99 return m.group(0).length - 7; 99 return (m.group(0).length - 7).toString();
100 }); 100 });
101 assertEquals("4, 2!", str); 101 assertEquals("4, 2!", str);
102 102
103 // Test capture that is a real substring. 103 // Test capture that is a real substring.
104 str = "Beasts of England, beasts of Ireland"; 104 str = "Beasts of England, beasts of Ireland";
105 str = str.replaceAll(new RegExp(r"(.*)"), '~'); 105 str = str.replaceAll(new RegExp(r"(.*)"), '~');
106 assertEquals("~~", str); 106 assertEquals("~~", str);
107 107
108 // Test zero-length matches that have non-zero-length sub-captures that do not 108 // Test zero-length matches that have non-zero-length sub-captures that do not
109 // start at the match start position. 109 // start at the match start position.
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 var crosscheck = "\x80"; 175 var crosscheck = "\x80";
176 for (var i = 0; i < 12; i++) crosscheck += crosscheck; 176 for (var i = 0; i < 12; i++) crosscheck += crosscheck;
177 new RegExp(crosscheck); 177 new RegExp(crosscheck);
178 178
179 var subject = "ascii~only~string~here~"; 179 var subject = "ascii~only~string~here~";
180 var replacement = "\x80"; 180 var replacement = "\x80";
181 var result = subject.replaceAll(new RegExp(r"~"), replacement); 181 var result = subject.replaceAll(new RegExp(r"~"), replacement);
182 for (var i = 0; i < 5; i++) result += result; 182 for (var i = 0; i < 5; i++) result += result;
183 new RegExp(result); 183 new RegExp(result);
184 } 184 }
OLDNEW
« no previous file with comments | « tests/corelib_2/regexp/find-first-asserted_test.dart ('k') | tests/corelib_2/regexp/indexof_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698