summaryrefslogtreecommitdiffstats
path: root/js/src/tests/ecma_6/String/make-normalize-generateddata-input.py
diff options
context:
space:
mode:
Diffstat (limited to 'js/src/tests/ecma_6/String/make-normalize-generateddata-input.py')
-rw-r--r--js/src/tests/ecma_6/String/make-normalize-generateddata-input.py70
1 files changed, 70 insertions, 0 deletions
diff --git a/js/src/tests/ecma_6/String/make-normalize-generateddata-input.py b/js/src/tests/ecma_6/String/make-normalize-generateddata-input.py
new file mode 100644
index 000000000..c1983dbd1
--- /dev/null
+++ b/js/src/tests/ecma_6/String/make-normalize-generateddata-input.py
@@ -0,0 +1,70 @@
+#!/usr/bin/python -B
+
+""" Usage: make-normalize-generateddata-input.py PATH_TO_MOZILLA_CENTRAL
+
+ This script generates test input data for String.prototype.normalize
+ from intl/icu/source/data/unidata/NormalizationTest.txt
+ to js/src/tests/ecma_6/String/normalize-generateddata-input.js
+"""
+
+from __future__ import print_function
+import re, sys
+
+sep_pat = re.compile(' +')
+def to_code_list(codes):
+ return '[' + ', '.join(map(lambda x: '0x{0}'.format(x), re.split(sep_pat, codes))) + ']'
+
+def convert(dir):
+ ver_pat = re.compile('NormalizationTest-([0-9\.]+)\.txt')
+ part_pat = re.compile('^@(Part([0-9]+) .+)$')
+ test_pat = re.compile('^([0-9A-Fa-f ]+);([0-9A-Fa-f ]+);([0-9A-Fa-f ]+);([0-9A-Fa-f ]+);([0-9A-Fa-f ]+);$')
+ ignore_pat = re.compile('^#|^$')
+ js_path = 'js/src/tests/ecma_6/String/normalize-generateddata-input.js'
+ txt_path = 'intl/icu/source/data/unidata/NormalizationTest.txt'
+
+ part_opened = False
+ not_empty = False
+ with open('{dir}/{path}'.format(dir=dir, path=txt_path), 'r') as f:
+ with open('{dir}/{path}'.format(dir=dir, path=js_path), 'w') as outf:
+ for line in f:
+ m = test_pat.search(line)
+ if m:
+ if not_empty:
+ outf.write(',')
+ outf.write('\n')
+ pat = '{{ source: {source}, NFC: {NFC}, NFD: {NFD}, NFKC: {NFKC}, NFKD: {NFKD} }}'
+ outf.write(pat.format(source=to_code_list(m.group(1)),
+ NFC=to_code_list(m.group(2)),
+ NFD=to_code_list(m.group(3)),
+ NFKC=to_code_list(m.group(4)),
+ NFKD=to_code_list(m.group(5))))
+ not_empty = True
+ continue
+ m = part_pat.search(line)
+ if m:
+ desc = m.group(1)
+ part = m.group(2)
+ if part_opened:
+ outf.write('\n];\n')
+ outf.write('/* {desc} */\n'.format(desc=desc))
+ outf.write('var tests_part{part} = ['.format(part=part))
+ part_opened = True
+ not_empty = False
+ continue
+ m = ver_pat.search(line)
+ if m:
+ ver = m.group(1)
+ outf.write('/* created from NormalizationTest-{ver}.txt */\n'.format(ver=ver))
+ continue
+ m = ignore_pat.search(line)
+ if m:
+ continue
+ print("Unknown line: {0}".format(line), file=sys.stderr)
+ if part_opened:
+ outf.write('\n];\n')
+
+if __name__ == '__main__':
+ if len(sys.argv) < 2:
+ print("Usage: make-normalize-generateddata-input.py PATH_TO_MOZILLA_CENTRAL", file=sys.stderr)
+ sys.exit(1)
+ convert(sys.argv[1])