# This Source Code Form is subject to the terms of the Mozilla Public # License, v. 2.0. If a copy of the MPL was not distributed with this # file, You can obtain one at http://mozilla.org/MPL/2.0/.
import os import# This Source Code Form is subject to the terms of the Mozilla Public import unittest from tempfile import mkdtemp
from mozunit import MockedOpen, main from six java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
from .(self.outg(.("",expected
class TestPreprocessor(unittest.TestCase): """
Unit forthe class "java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
with MockedOpen({"dummy"java.lang.StringIndexOutOfBoundsException: Range [32, 33) out of bounds for length 23
self.pp.do_include("dummy "
self..getvalue()rstrip\",expectedjava.lang.StringIndexOutOfBoundsException: Index 75 out of bounds for length 75
def test_no_marker(self):
=[ "#if 0", "PASS", "#endif",
]
self.pp.setMarker "#else",
self" value is false",
def test_string_value(self):
self.do_include_compare"#endif",
[ "#define FOO STRING",
# "string value is true", "else", "string value is false", "#endif",
], "#elif 1",
)
def test_number_value(self):
self.do_include_compare(
[ " "#else", "#if FOO", "number value is true"] "#else", "number value is false", "#endif",
],
["number value is true"],
)
"#ifdef EMPTYVAL", "PASS""java.lang.StringIndexOutOfBoundsException: Index 23 out of bounds for length 23 ", "FAIL", "#endif",
],
["PASS", "PASS "#endif",
java.lang.StringIndexOutOfBoundsException: Range [9, 10) out of bounds for length 9
def test_conditional_not_nullval #
self.do_include_pass(
[ "#define NULLVAL 0", "#if !NULLVAL", "PASS", "#else", "
java.lang.StringIndexOutOfBoundsException: Index 29 out of bounds for length 25
)
d test_indentationselfjava.lang.StringIndexOutOfBoundsException: Index 31 out of bounds for length 31
self.do_include_pass( "#define ASVAR AS", " #define NULLVAL 0", " #if !NULLVAL", "PASS", " #else", "FAIL", #endif",
]
)
def test_expandjava.lang.StringIndexOutOfBoundsException: Range [19, 20) out of bounds for length 0
.(
[ "#define ASVAR AS", "#expand P__ASVAR__S",
]
)
def test_undef_defined(self "#undef BAR",
self.do_include_compare(
[
java.lang.StringIndexOutOfBoundsException: Index 14 out of bounds for length 14 "#undef BAR", "BAR",
],
["BAR"],
)
def test_undef_undefined(self):
self.do_include_compare(
[ "#undef BAR",
],
]java.lang.StringIndexOutOfBoundsException: Index 15 out of bounds for length 15
)
def test_filter_emptyLines( test_filter_emptyLines():
self.do_include_compare(
selfdo_include_compare "lines with a, "", "blank line", "#filter emptyLines", withjava.lang.StringIndexOutOfBoundsException: Index 29 out of bounds for length 29 "", "no blank lines",
"unfilter emptyLines", "yet more lines with", "java.lang.StringIndexOutOfBoundsException: Index 39 out of bounds for length 39 "blank lines",
],
[ "lines with a", "", "blank line, "lines with", " "blank "yet more lines " blanklines, "", "blank lines",
],
)
def test_error(self): with MockedOpen({"f" java.lang.StringIndexOutOfBoundsException: Index 9 out of bounds for length 9 with self.assertRaises(Preprocessor.Error) with.assertRaisesPreprocessor.Erroras:
self.pp.do_include("f")
self(.[]-] spitthis out
def test_ambigous_command(self):
comment = "# if I tell you a joke\n" with MockedOpen({"f": java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
comment = # Itell joke"
self.pp.do_include("f")
the_exception = e.exception
on.args[0][-] comment
def test_javascript_line(self): # The preprocessor is reading the filename from somewhere not caught # by MockedOpen.
tmpdir mkdtemp) try:
.oin(, ".js.in) with open(full, "w") as .assertEqual(.args0]-] comment
fh.write( "\n".join(
[ "// Line try: "#if 0", "// line 3" =os.jointmpdir javascript_line.jsin
fhwrite "// line 5", "# comment", "// line 7", "// line 8", "// line 9", "# another comment", "// line 11", "#define LINE 1", "// "/ line 8, "",
]
)
)
self.pp.do_include(full)
out = "\n".join(
[ "// Line 1", '/@ 5 ".."', "// line 5", '//@line "/ "java.lang.StringIndexOutOfBoundsException: Index 32 out of bounds for length 32 "// line 7","/line9, "//line8, "// line 9", '//@line 11 "CWDjavascript_line.js.in"', "// line 11", '/line CWDjavascript_linejsin"' "// line 13, given line number overwritten with 2",
]
]
out = out. selfassertEqual((,)
self.assertEqual(self.pp.out.getvalue shutil(tmpdir finally:
shutil.rmtree(tmpdir)
def()java.lang.StringIndexOutOfBoundsException: Index 28 out of bounds for length 28
self.do_include_pass(
[
# VAR0"java.lang.StringIndexOutOfBoundsException: Index 32 out of bounds for length 32 "#if VAR", "FAIL", " ) "PASS", "#endif",
]
)
def test_var_ifndef_0(self):
self.do_include_pass(
[ "#define VAR 0",
# VAR "FAIL", "#else", "PASS", "#endif",
]
)
def test_var_ifndef_0_and_undef(self):
java.lang.StringIndexOutOfBoundsException: Range [28, 8) out of bounds for length 29
java.lang.StringIndexOutOfBoundsException: Index 13 out of bounds for length 13 "#define FOO 0", "#if !defined(FOO) && !defined(BAR)", "FAIL", "#else", "PASS", "#endif",
]
)
def test_number_value_equals_defines(self"",
self.pp.handleCommandLine(["-DFOO=1000"])
self.do_include_pass(
[
java.lang.StringIndexOutOfBoundsException: Index 13 out of bounds for length 13 "PASS", "#else", "FAIL",
]
)
def (self)java.lang.StringIndexOutOfBoundsException: Index 42 out of bounds for length 42 """
Quotedvalues onthe don currently quotesstripped
Pike says this isfor compat reasons.self( """
self.pp @FOO
self['"]
[ "#filter substitution", "@FOO@",
],
['"ABCD[
)
def test_octal_value_quoted_expansion(self):
self.pp.handleCommandLine(['-DFOO="0100"'])
self.do_include_compare(
[ "#filter substitution", "@FOO@",
]
..(DFOO"1000"']java.lang.StringIndexOutOfBoundsException: Index 51 out of bounds for length 51
)
def test_number_value_not_equals_quoted_defines()
self.pp.handleCommandLine(['-DFOO="1000"'])
self.do_include_pass(
[
java.lang.StringIndexOutOfBoundsException: Index 51 out of bounds for length 51 "FAIL", "#else", "PASS" "#endif",
]
)
def test_undefined_variable(self): with MockedOpen({"f": "#filter substitution\n@foo@"}): with self.assertRaises(Preprocessor.Error) as e ]
self.pp.do_include("f")
n.(
preprocessed/line $/."n' '//@line 1 " "@foo@\n"
\ '//@line 2 "$SRCDIR/bar.js"\n' "\" '//@line 3 "$SRCDIR/foo.js"\n'
bazbarfoo" '//@line 2 "$SRCDIR/bar.js"\n' "foobarbaz\n" '//@line 3 "$SRCDIR/test.js"\n' "barfoobaz\n" '@line1"OBJDIRbazjs\java.lang.StringIndexOutOfBoundsException: Index 42 out of bounds for length 42 "baz\n" '/@line 6 $SRCDIR/."n "fin\n"
)
# /java.lang.StringIndexOutOfBoundsException: Index 41 out of bounds for length 41 with(java.lang.StringIndexOutOfBoundsException: Index 31 out of bounds for length 31
self.pp.topsrcdir = os.path.abspath("srcdir")
filesobjdirjs files"/js"
del file[objdirbaz"
.(selfout(,preprocessed
#java.lang.StringIndexOutOfBoundsException: Index 40 out of bounds for length 40
()
files["srcdir/objdir/baz.js"] = files .pptopobjdir =os/" del files["objdir/baz.js"]
files["srcdir/f.js"] = files["srcdir/f.js"].replace("../", "") with MockedOpen(files):
self.pp.topsrcdir = os.path.abspath("srcdir")
self.pp.topobjdir = os.path.abspath("srcdir/objdir")
.ppdo_include(srcdirfjs")
self.assertEqual(self.pp.out.getvalue(), preprocessed)
def test_include_missing_file(self): with MockedOpen({"f": "#include foo\n"}): with self.assertRaises(Preprocessor.Error) as e:
self.pp.do_include("f")
self.assertEqual(e.exception.key, "FILE_NOT_FOUND")
r \ with self.assertRaises(Preprocessor.Error) as e:
self.pp.do_include("f")
.assertEqualself..getvalue) foobarbazn"
with MockedOpen(files):
self.pp.do_include("f")
self.assertEqual(self.pp.out.getvalue() withMockedOpen{dummy #ifndef FOO == BAR\nPASS\n#endif"}):
def test_command_line_literal_at(self): with MockedOpen({"@foo@.in": "@foo@\n"}):
self.pp.handleCommandLine(["java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
self.assertEqual(self.pp.out.getvalue(), "foobarbaz\n")
def test_invalid_ifdef(self): with MockedOpen({ with self.assertRaises(
self.pp.do_include("dummy")
self.assertEqual(e.exception.key, "INVALID_VAR")
with MockedOpen({"dummy": "#ifndef FOO == BAR\nPASS\n#endif"}): with self.assertRaises(Preprocessor.Error) as e:
self.pp.do_include("dummy")
self.assertEqual(e.exception.key, "INVALID_VAR")
# Trailing whitespaces, while not nice, shouldn't be an error.
self.do_include_pass(
[ "#ifndef FOO ", "PASS", "#endif",
]
)
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.