This repository has been archived by the owner on Dec 3, 2019. It is now read-only.
mirrored from https://chromium.googlesource.com/catapult
-
Notifications
You must be signed in to change notification settings - Fork 566
/
Copy pathjs_checks_unittest.py
78 lines (67 loc) · 2.18 KB
/
js_checks_unittest.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# Copyright 2015 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import unittest
from catapult_build import js_checks
class JsChecksTest(unittest.TestCase):
def testCheckStrictModeReturnsNoErrorsWhenAllScriptElementsAreStrict(self):
contents = """
<script> 'use strict'; var a = 1 + 1;
</script>
<br>
<script>
'use strict';
var b = 2 + 2;
</script>
"""
self.assertEqual(
[], js_checks.CheckStrictMode(contents, is_html_file=True))
def testCheckStrictModeReturnsNoErrorsWhenThereAreNoScriptTags(self):
contents = """
<div></div>
"""
self.assertEqual(
[], js_checks.CheckStrictMode(contents, is_html_file=True))
def testCheckStrictModeReturnsNoErrorsWhenJSFileIsStrict(self):
contents = """
'use strict';
var a = 1 + 1;
var b = 2 + 2;
"""
self.assertEqual(
[], js_checks.CheckStrictMode(contents, is_html_file=False))
def testCheckStrictModeWhenThereIsACommentAboveTheDeclaration(self):
contents = """
// This is a comment at the top
/* another comment which
spans two lines */
'use strict';
var a = 1 + 1;
var b = 2 + 2;
"""
self.assertEqual(
[], js_checks.CheckStrictMode(contents, is_html_file=False))
def testCheckStrictModeDoesntCheckExternalScriptElements(self):
contents = """
<script src="external.js"></script>
"""
self.assertEqual(
[], js_checks.CheckStrictMode(contents, is_html_file=True))
def testCheckStrictModeReturnsAnErrorWhenOneScriptElementIsNotStrict(self):
contents = """
<script> 'use strict'; var a = 1 + 1;
</script>
<br>
<script>
var b = 2 + 2;
</script>
"""
self.assertEqual(
1, len(js_checks.CheckStrictMode(contents, is_html_file=True)))
def testCheckStrictModeReturnsAnErrorWhenJSFileIsNonStrict(self):
contents = """
var a = 1 + 1;
var b = 2 + 2;
"""
self.assertEqual(
1, len(js_checks.CheckStrictMode(contents, is_html_file=False)))