diff options
author | Leo Balter <leonardo.balter@gmail.com> | 2016-05-31 17:45:48 -0400 |
---|---|---|
committer | Leo Balter <leonardo.balter@gmail.com> | 2016-05-31 17:45:48 -0400 |
commit | 1e75730d5f26b1c5dc63ecf85d610ed0c6297558 (patch) | |
tree | a2993fca6fa09fdb6573a90fe082833db59817f2 /tools | |
parent | 30d4c04182a9c2be88a8bf3dc4a3fd54b44c5ebf (diff) | |
parent | d8c686e310e14eebcea66e7a11baf00a86849945 (diff) | |
download | qtdeclarative-testsuites-1e75730d5f26b1c5dc63ecf85d610ed0c6297558.tar.gz |
Merge pull request #587 from bocoup/generation-annexb-fns
Add tests for Annex B "function in block" semantics (procedurally generated)
Diffstat (limited to 'tools')
-rwxr-xr-x | tools/generation/generator.py | 12 | ||||
-rw-r--r-- | tools/generation/lib/template.py | 7 | ||||
-rw-r--r-- | tools/generation/lib/util/find_comments.py | 7 | ||||
-rw-r--r-- | tools/generation/test/expected/normal/path1-normal.js | 7 | ||||
-rw-r--r-- | tools/generation/test/fixtures/normal.case | 2 | ||||
-rw-r--r-- | tools/generation/test/fixtures/normal/normal.template | 7 |
6 files changed, 32 insertions, 10 deletions
diff --git a/tools/generation/generator.py b/tools/generation/generator.py index d2235abd3..64a0ccf0b 100755 --- a/tools/generation/generator.py +++ b/tools/generation/generator.py @@ -12,15 +12,21 @@ from lib.test import Test def print_error(*values): print('ERROR:', *values, file=sys.stderr) +# When a directory contains at least one file with a `.case` extension, it +# should be interpreted as a "case directory" +def is_case_dir(location): + for file_name in os.listdir(location): + if file_name.lower().endswith('.case'): + return True + return False + def find_cases(location): # When a file is specified, return the file name and its containing # directory if os.path.isfile(location): return location, [os.path.dirname(location)] - # When a directory is specified, if that directory contains a sub-directory - # names "default" interpret it as a "case directory" - if (os.path.isdir(os.path.join(location, 'default'))): + if is_case_dir(location): return None, [location] else: return None, map( diff --git a/tools/generation/lib/template.py b/tools/generation/lib/template.py index f3255ed97..769ec4fb9 100644 --- a/tools/generation/lib/template.py +++ b/tools/generation/lib/template.py @@ -82,6 +82,13 @@ class Template: for region in self.regions: whitespace = indentPattern.match(lines[region['lineno']]).group(1) value = context['regions'].get(region['name'], '') + + str_char = region.get('in_string') + if str_char: + safe_char = '"' if str_char == '\'' else '\'' + value = value.replace(str_char, safe_char) + value = value.replace('\n', '\\\n') + source = source[:region['firstchar']] + \ indent(value, whitespace).lstrip() + \ source[region['lastchar']:] diff --git a/tools/generation/lib/util/find_comments.py b/tools/generation/lib/util/find_comments.py index 81ad0ab55..bf4b0ffd7 100644 --- a/tools/generation/lib/util/find_comments.py +++ b/tools/generation/lib/util/find_comments.py @@ -4,6 +4,7 @@ def find_comments(source): '''Parse input string describing JavaScript source and yield dictionaries describing the JavaScript comments in the order they appear in the source. + This includes comment patterns within string literals. Each dictionary defines the following attributes: @@ -11,6 +12,9 @@ def find_comments(source): - firstchar: the zero-indexed position of the token that begins the comment - lastchar: the zero-indexed position of the token that closes the comment - lineno: the zero-indexed offset of the line on which the comment appears + - in_string: `False` if the comment is a true JavaScript comment, one of + '\'' (single quote), '"' (double quote), or '`' (back tick) if + the comment pattern appears within a string literal. ''' in_string = False in_s_comment = False @@ -37,6 +41,7 @@ def find_comments(source): source=comment[1:], firstchar=idx - len(comment) - 1, lastchar=idx, + in_string=in_string, lineno=lineno) continue elif in_m_comment: @@ -46,6 +51,7 @@ def find_comments(source): source=comment[1:-1], firstchar=idx - len(comment) - 1, lastchar=idx + 1, + in_string=in_string, lineno=lineno) continue elif in_string: @@ -53,7 +59,6 @@ def find_comments(source): in_string = False elif source[idx] == '\n' and in_string != '`' and not follows_escape: in_string = False - continue if in_m_comment or in_s_comment: comment += source[idx] diff --git a/tools/generation/test/expected/normal/path1-normal.js b/tools/generation/test/expected/normal/path1-normal.js index 7e00fbe6b..e80120c38 100644 --- a/tools/generation/test/expected/normal/path1-normal.js +++ b/tools/generation/test/expected/normal/path1-normal.js @@ -25,9 +25,10 @@ The following should not be expanded: */*{ first }*/ //*{ first }*/ // /*{ first }*/ -"/*{ first }*/" -'/*{ first }*/' +Quote characters: " ' ` +"Quote characters: ' ' `" +'Quote characters: " " `' ` -/*{ first }*/` +Quote characters: " ' '` 'This is "teardown" code.'; diff --git a/tools/generation/test/fixtures/normal.case b/tools/generation/test/fixtures/normal.case index 276b58ccd..c97a6e7b7 100644 --- a/tools/generation/test/fixtures/normal.case +++ b/tools/generation/test/fixtures/normal.case @@ -23,5 +23,7 @@ First value Second value //- third Third value +//- fourth +Quote characters: " ' ` //- teardown 'This is "teardown" code.'; diff --git a/tools/generation/test/fixtures/normal/normal.template b/tools/generation/test/fixtures/normal/normal.template index ac0bea1e1..32bc9cff1 100644 --- a/tools/generation/test/fixtures/normal/normal.template +++ b/tools/generation/test/fixtures/normal/normal.template @@ -21,7 +21,8 @@ The following should not be expanded: */*{ first }*/ //*{ first }*/ // /*{ first }*/ -"/*{ first }*/" -'/*{ first }*/' +/*{ fourth }*/ +"/*{ fourth }*/" +'/*{ fourth }*/' ` -/*{ first }*/` +/*{ fourth }*/` |