blob: 94f86c344e1460cdb12ad79d0f8be9f914d3236b [file] [log] [blame]
// Copyright (c) 2017, 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 String replaceAllMapped(Pattern from, String replace(Match match))
* ...
* The replace function is called with the Match generated by the pattern, and
* its result is used as replacement
* @description Checks that the replace function is called with the Match
* generated by the pattern, and its result is used as replacement
* @author sgrekhov@unipro.ru
*/
import "../../../Utils/expect.dart";
main() {
check("123", "1", [[0, 1]]);
check("1231", "1", [[0, 1], [3, 4]]);
check("1231", "12", [[0, 2]]);
check("1231", "23", [[1, 3]]);
check("aa 1231\\n", new RegExp("\\s"), [[2, 3], [7, 8]]);
}
check(String str, Pattern from, List expected) {
int count = 0;
str.replaceAllMapped(from, (m) {
var expData = expected[count++];
Expect.equals(str, m.input);
Expect.equals(from, m.pattern);
Expect.equals(expData[0], m.start);
Expect.equals(expData[1], m.end);
return "";
});
}