Debian Codegraph @

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

raw symbols SCIP
1 /*
2 * Copyright 2009 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.rhino.Node;
20 import com.google.javascript.rhino.Token;
21
22 import junit.framework.TestCase;
23
24 /**
25 * A dopey test for {@link MemoizedScopeCreator}. This is mostly here
26 * just so it's easy to write more tests if this becomes more complicated.
27 *
28 * @author [email protected] (Nick Santos)
29 */
30 public class MemoizedScopeCreatorTest extends TestCase {
31
32 public void testMemoization() throws Exception {
33 Node trueNode = new Node(Token.TRUE);
34 Node falseNode = new Node(Token.FALSE);
35 // Wow, is there really a circular dependency between JSCompiler and
36 // SyntacticScopeCreator?
37 Compiler compiler = new Compiler();
38 compiler.initOptions(new CompilerOptions());
39 ScopeCreator creator = new MemoizedScopeCreator(
40 new SyntacticScopeCreator(compiler));
41 Scope scopeA = creator.createScope(trueNode, null);
42 assertSame(scopeA, creator.createScope(trueNode, null));
43 assertNotSame(scopeA, creator.createScope(falseNode, null));
44 }
45
46 public void testPreconditionCheck() throws Exception {
47 Compiler compiler = new Compiler();
48 compiler.initOptions(new CompilerOptions());
49 Node trueNode = new Node(Token.TRUE);
50 ScopeCreator creator = new MemoizedScopeCreator(
51 new SyntacticScopeCreator(compiler));
52 Scope scopeA = creator.createScope(trueNode, null);
53
54 boolean handled = false;
55 try {
56 creator.createScope(trueNode, scopeA);
57 } catch (IllegalStateException e) {
58 handled = true;
59 }
60 assertTrue(handled);
61 }
62
63 }