def test_notif_inline(self): i=nl("IF_NOT_FEATURE_IPV6(sa_family_t af = AF_INET)") o=""" #if !defined CONFIG_FEATURE_IPV6 sa_family_t af = AF_INET #endif""" self.equal_test(i, o)
def test_notif_inline(self): i = nl("IF_NOT_FEATURE_IPV6(sa_family_t af = AF_INET)") o = """ #if !defined CONFIG_FEATURE_IPV6 sa_family_t af = AF_INET #endif""" self.equal_test(i, o)
def test_if_inline2(self): i=nl("IF_FEATURE_FIND_PATH(ACTS(path, const char *pattern; bool ipath;))") o=""" #if defined CONFIG_FEATURE_FIND_PATH ACTS(path, const char *pattern; bool ipath;) #endif""" self.equal_test(i, o)
def test_noops(self): for l in ['#if 0', '#else', '#endif', '#define CONFIG_FOO 1', '#define CONFIG_BAR 0' ' a;', # do not eat leading spaces 'code(); //usage #if IF_FEATURE_ACPID_COMPACT(' ]: self.equal_test(nl(l), l)
def test_IF_FEATURE_inline(self): i = nl("""IF_DESKTOP(long long) int bz_write(bz_stream *strm, void* rbuf, ssize_t rlen, void *wbuf) {""") o = """ #if defined CONFIG_DESKTOP long long #endif int bz_write(bz_stream *strm, void* rbuf, ssize_t rlen, void *wbuf) {""" self.equal_test(i, o)
def test_if_inline2(self): i = nl( "IF_FEATURE_FIND_PATH(ACTS(path, const char *pattern; bool ipath;))" ) o = """ #if defined CONFIG_FEATURE_FIND_PATH ACTS(path, const char *pattern; bool ipath;) #endif""" self.equal_test(i, o)
def test_ENABLE_inline3(self): i = nl(" char day_headings[ENABLE_UNICODE_SUPPORT ? 28 * 6 : 28];") o = """\tchar day_headings[ #if defined CONFIG_UNICODE_SUPPORT 1 #else 0 #endif ? 28 * 6 : 28];""" self.equal_test(i, o)
def test_ENABLE_inline3(self): i=nl(" char day_headings[ENABLE_UNICODE_SUPPORT ? 28 * 6 : 28];") o="""\tchar day_headings[ #if defined CONFIG_UNICODE_SUPPORT 1 #else 0 #endif ? 28 * 6 : 28];""" self.equal_test(i, o)
def test_ENABLE_inline2(self): i = nl("if (ENABLE_FEATURE_USB)") o = """if ( #if defined CONFIG_FEATURE_USB 1 #else 0 #endif )""" self.equal_test(i, o)
def test_ENABLE_inline2(self): i=nl("if (ENABLE_FEATURE_USB)") o="""if ( #if defined CONFIG_FEATURE_USB 1 #else 0 #endif )""" self.equal_test(i, o)
def test_noops(self): for l in [ '#if 0', '#else', '#endif', '#define CONFIG_FOO 1', '#define CONFIG_BAR 0' ' a;', # do not eat leading spaces 'code(); //usage #if IF_FEATURE_ACPID_COMPACT(' ]: self.equal_test(nl(l), l)
def test_IF_FEATURE_inline(self): i = nl( """IF_DESKTOP(long long) int bz_write(bz_stream *strm, void* rbuf, ssize_t rlen, void *wbuf) {""" ) o = """ #if defined CONFIG_DESKTOP long long #endif int bz_write(bz_stream *strm, void* rbuf, ssize_t rlen, void *wbuf) {""" self.equal_test(i, o)
def equal_test(self, i, o): """ runs normalizer on each line ensures that the input string i is equal to the reference string o """ r = list() i = i.replace("\\\n", "\\") i = i.replace("\\", "") for line in i.splitlines(): out = nl(line) if len(out) > 0: lines = out.splitlines() for res_line in lines: r.append(res_line) else: r.append(out) self.assertEqual(r, o.splitlines())
def test_defined_normalizations(self): self.assertEqual(nl("#if ENABLE_FEATURE_USB"), "#if defined CONFIG_FEATURE_USB") self.assertEqual( nl("#if ENABLE_HUSH_IF || ENABLE_HUSH_LOOPS"), "#if defined CONFIG_HUSH_IF || defined CONFIG_HUSH_LOOPS")
def test_not_ENABLE_line_continuation(self): i = nl("""#if !ENABLE_DESKTOP \\""") o = nl("""#if !ENABLE_DESKTOP """) self.equal_test(i, o)
def test_defined_normalizations(self): self.assertEqual(nl("#if ENABLE_FEATURE_USB"), "#if defined CONFIG_FEATURE_USB") self.assertEqual(nl("#if ENABLE_HUSH_IF || ENABLE_HUSH_LOOPS"), "#if defined CONFIG_HUSH_IF || defined CONFIG_HUSH_LOOPS")