@@ -316,15 +316,16 @@ class TestSimplifyTokens : public TestFixture {
316
316
return tokenizer.tokens ()->stringifyList (0 , !simplify);
317
317
}
318
318
319
- std::string tok (const char code[], const char filename[]) {
319
+ std::string tok (const char code[], const char filename[], bool simplify = true ) {
320
320
errout.str (" " );
321
321
322
322
Settings settings;
323
323
Tokenizer tokenizer (&settings, this );
324
324
325
325
std::istringstream istr (code);
326
326
tokenizer.tokenize (istr, filename);
327
- tokenizer.simplifyTokenList2 ();
327
+ if (simplify)
328
+ tokenizer.simplifyTokenList2 ();
328
329
329
330
return tokenizer.tokens ()->stringifyList (0 , false );
330
331
}
@@ -1684,68 +1685,71 @@ class TestSimplifyTokens : public TestFixture {
1684
1685
}
1685
1686
1686
1687
void not1 () {
1687
- ASSERT_EQUALS (" void f ( ) { if ( ! p ) { ; } }" , tok (" void f() { if (not p); }" , false ));
1688
- ASSERT_EQUALS (" void f ( ) { if ( p && ! q ) { ; } }" , tok (" void f() { if (p && not q); }" , false ));
1689
- ASSERT_EQUALS (" void f ( ) { a = ! ( p && q ) ; }" , tok (" void f() { a = not(p && q); }" , false ));
1688
+ ASSERT_EQUALS (" void f ( ) { if ( ! p ) { ; } }" , tok (" void f() { if (not p); }" , " test.c " , false ));
1689
+ ASSERT_EQUALS (" void f ( ) { if ( p && ! q ) { ; } }" , tok (" void f() { if (p && not q); }" , " test.c " , false ));
1690
+ ASSERT_EQUALS (" void f ( ) { a = ! ( p && q ) ; }" , tok (" void f() { a = not(p && q); }" , " test.c " , false ));
1690
1691
// Don't simplify 'not' or 'compl' if they are defined as a type;
1691
1692
// in variable declaration and in function declaration/definition
1692
- ASSERT_EQUALS (" struct not { int x ; } ;" , tok (" struct not { int x; };" , false ));
1693
- ASSERT_EQUALS (" void f ( ) { not p ; compl c ; }" , tok (" void f() { not p; compl c; }" , false ));
1694
- ASSERT_EQUALS (" void foo ( not i ) ;" , tok (" void foo(not i);" , false ));
1695
- ASSERT_EQUALS (" int foo ( not i ) { return g ( i ) ; }" , tok (" int foo(not i) { return g(i); }" , false ));
1693
+ ASSERT_EQUALS (" struct not { int x ; } ;" , tok (" struct not { int x; };" , " test.c " , false ));
1694
+ ASSERT_EQUALS (" void f ( ) { not p ; compl c ; }" , tok (" void f() { not p; compl c; }" , " test.c " , false ));
1695
+ ASSERT_EQUALS (" void foo ( not i ) ;" , tok (" void foo(not i);" , " test.c " , false ));
1696
+ ASSERT_EQUALS (" int foo ( not i ) { return g ( i ) ; }" , tok (" int foo(not i) { return g(i); }" , " test.c " , false ));
1696
1697
}
1697
1698
1698
1699
void and1 () {
1699
1700
ASSERT_EQUALS (" void f ( ) { if ( p && q ) { ; } }" ,
1700
- tok (" void f() { if (p and q) ; }" , false ));
1701
+ tok (" void f() { if (p and q) ; }" , " test.c " , false ));
1701
1702
1702
1703
ASSERT_EQUALS (" void f ( ) { if ( foo ( ) && q ) { ; } }" ,
1703
- tok (" void f() { if (foo() and q) ; }" , false ));
1704
+ tok (" void f() { if (foo() and q) ; }" , " test.c " , false ));
1704
1705
1705
1706
ASSERT_EQUALS (" void f ( ) { if ( foo ( ) && bar ( ) ) { ; } }" ,
1706
- tok (" void f() { if (foo() and bar()) ; }" , false ));
1707
+ tok (" void f() { if (foo() and bar()) ; }" , " test.c " , false ));
1707
1708
1708
1709
ASSERT_EQUALS (" void f ( ) { if ( p && bar ( ) ) { ; } }" ,
1709
- tok (" void f() { if (p and bar()) ; }" , false ));
1710
+ tok (" void f() { if (p and bar()) ; }" , " test.c " , false ));
1710
1711
1711
1712
ASSERT_EQUALS (" void f ( ) { if ( p && ! q ) { ; } }" ,
1712
- tok (" void f() { if (p and not q) ; }" , false ));
1713
+ tok (" void f() { if (p and not q) ; }" , " test.c " , false ));
1713
1714
1714
1715
ASSERT_EQUALS (" void f ( ) { r = a && b ; }" ,
1715
- tok (" void f() { r = a and b; }" , false ));
1716
+ tok (" void f() { r = a and b; }" , " test.c " , false ));
1716
1717
1717
1718
ASSERT_EQUALS (" void f ( ) { r = ( a || b ) && ( c || d ) ; }" ,
1718
- tok (" void f() { r = (a || b) and (c || d); }" , false ));
1719
+ tok (" void f() { r = (a || b) and (c || d); }" , " test.c" , false ));
1720
+
1721
+ ASSERT_EQUALS (" void f ( ) { if ( test1 [ i ] == 'A' && test2 [ i ] == 'C' ) { } }" ,
1722
+ tok (" void f() { if (test1[i] == 'A' and test2[i] == 'C') {} }" , " test.c" , false ));
1719
1723
}
1720
1724
1721
1725
void or1 () {
1722
1726
ASSERT_EQUALS (" void f ( ) { if ( p || q ) { ; } }" ,
1723
- tok (" void f() { if (p or q) ; }" , false ));
1727
+ tok (" void f() { if (p or q) ; }" , " test.c " , false ));
1724
1728
1725
1729
ASSERT_EQUALS (" void f ( ) { if ( foo ( ) || q ) { ; } }" ,
1726
- tok (" void f() { if (foo() or q) ; }" , false ));
1730
+ tok (" void f() { if (foo() or q) ; }" , " test.c " , false ));
1727
1731
1728
1732
ASSERT_EQUALS (" void f ( ) { if ( foo ( ) || bar ( ) ) { ; } }" ,
1729
- tok (" void f() { if (foo() or bar()) ; }" , false ));
1733
+ tok (" void f() { if (foo() or bar()) ; }" , " test.c " , false ));
1730
1734
1731
1735
ASSERT_EQUALS (" void f ( ) { if ( p || bar ( ) ) { ; } }" ,
1732
- tok (" void f() { if (p or bar()) ; }" , false ));
1736
+ tok (" void f() { if (p or bar()) ; }" , " test.c " , false ));
1733
1737
1734
1738
ASSERT_EQUALS (" void f ( ) { if ( p || ! q ) { ; } }" ,
1735
- tok (" void f() { if (p or not q) ; }" , false ));
1739
+ tok (" void f() { if (p or not q) ; }" , " test.c " , false ));
1736
1740
1737
1741
ASSERT_EQUALS (" void f ( ) { r = a || b ; }" ,
1738
- tok (" void f() { r = a or b; }" , false ));
1742
+ tok (" void f() { r = a or b; }" , " test.c " , false ));
1739
1743
1740
1744
ASSERT_EQUALS (" void f ( ) { r = ( a && b ) || ( c && d ) ; }" ,
1741
- tok (" void f() { r = (a && b) or (c && d); }" , false ));
1745
+ tok (" void f() { r = (a && b) or (c && d); }" , " test.c " , false ));
1742
1746
}
1743
1747
1744
1748
void cAlternativeTokens () {
1745
1749
ASSERT_EQUALS (" void f ( ) { err = err | ( ( r & s ) && ! t ) ; }" ,
1746
- tok (" void f() { err or_eq ((r bitand s) and not t); }" , false ));
1750
+ tok (" void f() { err or_eq ((r bitand s) and not t); }" , " test.c " , false ));
1747
1751
ASSERT_EQUALS (" void f ( ) const { r = f ( a [ 4 ] | 15 , ~ c , ! d ) ; }" ,
1748
- tok (" void f() const { r = f(a[4] bitor 0x0F, compl c, not d) ; }" , false ));
1752
+ tok (" void f() const { r = f(a[4] bitor 0x0F, compl c, not d) ; }" , " test.c " , false ));
1749
1753
1750
1754
}
1751
1755
0 commit comments