def test_strip_comments(self):
     self.assertEquals('A ', strip_js_comments.StripJSComments('A // foo'))
     self.assertEquals('A bar',
                       strip_js_comments.StripJSComments('A // foo\nbar'))
     self.assertEquals('A  b',
                       strip_js_comments.StripJSComments('A /* foo */ b'))
     self.assertEquals('A  b',
                       strip_js_comments.StripJSComments('A /* foo\n */ b'))
    def GetStrippedJSForFilename(self, filename, early_out_if_no_tvcm):
        if filename in self.stripped_js_by_filename:
            return self.stripped_js_by_filename[filename]

        with open(filename, 'r') as f:
            contents = f.read(4096)
        if early_out_if_no_tvcm and ('tvcm' not in contents):
            return None

        s = strip_js_comments.StripJSComments(contents)
        self.stripped_js_by_filename[filename] = s
        return s
示例#3
0
def IsJSTest(text, text_is_stripped=True):
  if text_is_stripped:
    stripped_text = text
  else:
    stripped_text = strip_js_comments.StripJSComments(text)
  if re.search("""tvcm\s*\.\s*unittest\s*\.\s*testSuite\((["'])(.+?)\\1""",
               stripped_text, re.DOTALL):
    return True
  if re.search("""tvcm\s*\.\s*testSuite\((["'])(.+?)\\1""",
               stripped_text, re.DOTALL):
    return True

  return False
示例#4
0
def IsJSModule(text, text_is_stripped=True):
  if text_is_stripped:
    stripped_text = text
  else:
    stripped_text = strip_js_comments.StripJSComments(text)
  if re.search("""tvcm\s*\.\s*exportTo""",
               stripped_text, re.DOTALL):
    return True

  if re.search("""tvcm\s*\.\s*require""",
               stripped_text, re.DOTALL):
    return True

  if IsJSTest(stripped_text, text_is_stripped=True):
    return True

  return False
示例#5
0
 def test_ValidateUsesStrictMode_catches_missing_strict_mode(self):
   text = "// blahblahblah\n\ntvcm.require('dependency1');"
   stripped_text = strip_js_comments.StripJSComments(text)
   self.assertRaises(
       lambda: js_utils.ValidateUsesStrictMode('module', stripped_text))
示例#6
0
 def test_ValidateUsesStrictModeOneLiner(self):
   text = "'use strict'; tvcm.require('dependency1');"
   stripped_text = strip_js_comments.StripJSComments(text)
   self.assertIsNone(js_utils.ValidateUsesStrictMode('module', stripped_text))
示例#7
0
 def test_ValidateUsesStrictMode_returns_true(self):
   text = "// blahblahblah\n\n'use strict';\n\ntvcm.require('dependency1');"
   stripped_text = strip_js_comments.StripJSComments(text)
   self.assertIsNone(js_utils.ValidateUsesStrictMode('module', stripped_text))
示例#8
0
 def stripped_contents(self):
   if not self._stripped_contents:
     self._stripped_contents = strip_js_comments.StripJSComments(
         self.contents)
   return self._stripped_contents