Debian Codegraph @

test/com/google/javascript/jscomp/GlobalNamespaceTest.java

raw symbols SCIP
1 /*
2 * Copyright 2008 The Closure Compiler Authors.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 package com.google.javascript.jscomp;
18
19 import com.google.javascript.jscomp.GlobalNamespace.Name;
20 import com.google.javascript.jscomp.GlobalNamespace.Ref;
21
22 import junit.framework.TestCase;
23
24 /**
25 * Tests for {@link GlobalNamespace}.
26 *
27 * @author [email protected] (Nick Santos)
28 */
29 public class GlobalNamespaceTest extends TestCase {
30
31 public void testRemoveDeclaration1() {
32 Name n = new Name("a", null, false);
33 Ref set1 = createNodelessRef(Ref.Type.SET_FROM_GLOBAL);
34 Ref set2 = createNodelessRef(Ref.Type.SET_FROM_GLOBAL);
35
36 n.addRef(set1);
37 n.addRef(set2);
38
39 assertEquals(set1, n.getDeclaration());
40 assertEquals(2, n.globalSets);
41 assertEquals(2, n.getRefs().size());
42
43 n.removeRef(set1);
44
45 assertEquals(set2, n.getDeclaration());
46 assertEquals(1, n.globalSets);
47 assertEquals(1, n.getRefs().size());
48 }
49
50 public void testRemoveDeclaration2() {
51 Name n = new Name("a", null, false);
52 Ref set1 = createNodelessRef(Ref.Type.SET_FROM_GLOBAL);
53 Ref set2 = createNodelessRef(Ref.Type.SET_FROM_LOCAL);
54
55 n.addRef(set1);
56 n.addRef(set2);
57
58 assertEquals(set1, n.getDeclaration());
59 assertEquals(1, n.globalSets);
60 assertEquals(1, n.localSets);
61 assertEquals(2, n.getRefs().size());
62
63 n.removeRef(set1);
64
65 assertEquals(null, n.getDeclaration());
66 assertEquals(0, n.globalSets);
67 }
68
69 private Ref createNodelessRef(Ref.Type type) {
70 return Ref.createRefForTesting(type);
71 }
72 }