OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 import "package:compiler/src/js_backend/js_backend.dart" show TokenScope; |
| 6 |
| 7 import "package:expect/expect.dart"; |
| 8 |
| 9 String forwardN(TokenScope scope, int N) { |
| 10 for (int i = 1; i < N; ++i) { |
| 11 scope.getNextName(); |
| 12 } |
| 13 |
| 14 return scope.getNextName(); |
| 15 } |
| 16 |
| 17 int main() { |
| 18 // Test a normal scope. |
| 19 TokenScope scope = new TokenScope(); |
| 20 |
| 21 // We start with 'a'. |
| 22 Expect.equals("a", scope.getNextName()); |
| 23 // We have 24 lower case characters, as s and g are illegal. |
| 24 Expect.equals("A", forwardN(scope, 24)); |
| 25 // Make it overflow by skipping all uppercase. |
| 26 Expect.equals("a_", forwardN(scope, 26)); |
| 27 // Now numbers. |
| 28 Expect.equals("a0", forwardN(scope, 1)); |
| 29 Expect.equals("a9", forwardN(scope, 9)); |
| 30 // Then lower case letters. |
| 31 Expect.equals("aa", forwardN(scope, 1)); |
| 32 Expect.equals("az", forwardN(scope, 25)); |
| 33 // Then upper case letters |
| 34 Expect.equals("aA", forwardN(scope, 1)); |
| 35 Expect.equals("aZ", forwardN(scope, 25)); |
| 36 // Overflow to first position. |
| 37 Expect.equals("b_", forwardN(scope, 1)); |
| 38 // Make sure we skipe g. We have 1 + 10 + 26 + 26 = 63 digits. |
| 39 Expect.equals("h_", forwardN(scope, 63 * 5)); |
| 40 // Likewise, ensure we skip s. |
| 41 Expect.equals("t_", forwardN(scope, 63 * 11)); |
| 42 // And wrap around another digit. |
| 43 Expect.equals("a__", forwardN(scope, 63 * 33)); |
| 44 |
| 45 // Test a filtered scope. |
| 46 Set<String> illegal = new Set.from(["b", "aa"]); |
| 47 scope = new TokenScope(illegal); |
| 48 |
| 49 // We start with 'a'. |
| 50 Expect.equals("a", forwardN(scope, 1)); |
| 51 // Make sure 'b' is skipped. |
| 52 Expect.equals("c", forwardN(scope, 1)); |
| 53 // We have 24 lower case characters, as s and g are illegal. |
| 54 Expect.equals("A", forwardN(scope, 22)); |
| 55 // Make it overflow by skipping all uppercase. |
| 56 Expect.equals("a_", forwardN(scope, 26)); |
| 57 // Now numbers. |
| 58 Expect.equals("a0", forwardN(scope, 1)); |
| 59 Expect.equals("a9", forwardN(scope, 9)); |
| 60 // Make sure 'aa' is skipped on wrapping |
| 61 Expect.equals("ab", forwardN(scope, 1)); |
| 62 Expect.equals("az", forwardN(scope, 24)); |
| 63 } |
OLD | NEW |