blob: 65e27ec5015a4c6a1c3987d1b2dbf3de92b31efa [file] [log] [blame]
// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
/// @assertion An Atom followed by a Quantifier is repeated the
/// number of times specified by the Quantifier. A Quantifier can be non-greedy,
/// in which case the Atom pattern is repeated as few times as possible while
/// still matching the sequel, or it can be greedy, in which case the Atom
/// pattern is repeated as many times as possible while still matching the
/// sequel. The Atom pattern is repeated rather than the input String that it
/// matches, so different repetitions of the Atom can match different input
/// substrings.
/// @description Checks that greedy and non-greedy quantifiers work as expected.
/// @3rdparty sputnik-v1:S15.10.2.5_A1_T1.js-S15.10.2.5_A1_T2.js
/// @author rodionov
import "../../../../Utils/expect.dart";
main() {
check("a[a-z]{2,4}", "abcdefghi", ["abcde"]);
check("a[a-z]{2,4}?", "abcdefghi", ["abc"]);
void check(String pattern, String str, List<String> expectedGroups) {
RegExp re = new RegExp(pattern);
Match fm = re.firstMatch(str) as Match;
if(null != expectedGroups) {
Expect.equals(expectedGroups.length, fm.groupCount + 1);
for(int i = 0; i <= fm.groupCount; i++) {
String? expGr = expectedGroups[i];
String? actGr =;
Expect.equals(expGr, actGr,
"Mismatch at group $i: \"$expGr\" expected instead of \"$actGr\"");