Debian Codegraph @

test/com/google/javascript/jscomp/CheckMissingGetCssNameTest.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 /**
20 * @author [email protected] (Martin Kretzschmar)
21 */
22 public class CheckMissingGetCssNameTest extends CompilerTestCase {
23 @Override
24 protected CompilerPass getProcessor(final Compiler compiler) {
25 return new CombinedCompilerPass(
26 compiler,
27 new CheckMissingGetCssName(compiler, CheckLevel.ERROR, "goog-[a-z-]*"));
28 }
29
30 public void testMissingGetCssName() {
31 testMissing("var s = 'goog-inline-block'");
32 testMissing("var s = 'CSS_FOO goog-menu'");
33 testMissing("alert('goog-inline-block ' + goog.getClassName('CSS_FOO'))");
34 testMissing("html = '<div class=\"goog-special-thing\">Hello</div>'");
35 }
36
37 public void testRecognizeGetCssName() {
38 testNotMissing("var s = goog.getCssName('goog-inline-block')");
39 }
40
41 public void testIgnoreGetUniqueIdArguments() {
42 testNotMissing("var s = goog.events.getUniqueId('goog-some-event')");
43 testNotMissing("var s = joe.random.getUniqueId('joe-is-a-goob')");
44 }
45
46 public void testIgnoreAssignmentsToIdConstant() {
47 testNotMissing("SOME_ID = 'goog-some-id'");
48 testNotMissing("SOME_PRIVATE_ID_ = 'goog-some-id'");
49 testNotMissing("var SOME_ID_ = 'goog-some-id'");
50 }
51
52 public void testNotMissingGetCssName() {
53 testNotMissing("s = 'not-a-css-name'");
54 testNotMissing("s = 'notagoog-css-name'");
55 }
56
57 public void testDontCrashIfTheresNoQualifiedName() {
58 testMissing("things[2].DONT_CARE_ABOUT_THIS_KIND_OF_ID = "
59 + "'goog-inline-block'");
60 testMissing("objects[3].doSomething('goog-inline-block')");
61 }
62
63 private void testMissing(String js) {
64 test(js, js, CheckMissingGetCssName.MISSING_GETCSSNAME);
65 }
66
67 private void testNotMissing(String js) {
68 test(js, js);
69 }
70 }