aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorShevek <[email protected]>2015-11-17 12:48:58 -0800
committerShevek <[email protected]>2015-11-17 12:48:58 -0800
commita031457d300215a11df39ea6da5344af20555ee7 (patch)
tree1868ea453bd36e4568d3956429391cc31565f6de
parent3a2c42d80f49e0d5c3bc862fff30b7c22af667a7 (diff)
Test case for #24.
-rw-r--r--src/main/java/org/anarres/cpp/Feature.java2
-rw-r--r--src/test/java/org/anarres/cpp/VaArgsPastingTest.java63
2 files changed, 64 insertions, 1 deletions
diff --git a/src/main/java/org/anarres/cpp/Feature.java b/src/main/java/org/anarres/cpp/Feature.java
index 76c582d..a514269 100644
--- a/src/main/java/org/anarres/cpp/Feature.java
+++ b/src/main/java/org/anarres/cpp/Feature.java
@@ -29,7 +29,7 @@ public enum Feature {
LINEMARKERS,
/** Reports tokens of type INVALID as errors. */
CSYNTAX,
- /** Preserves comments in the lexed output. */
+ /** Preserves comments in the lexed output. Like cpp -C */
KEEPCOMMENTS,
/** Preserves comments in the lexed output, even when inactive. */
KEEPALLCOMMENTS,
diff --git a/src/test/java/org/anarres/cpp/VaArgsPastingTest.java b/src/test/java/org/anarres/cpp/VaArgsPastingTest.java
new file mode 100644
index 0000000..7623ebf
--- /dev/null
+++ b/src/test/java/org/anarres/cpp/VaArgsPastingTest.java
@@ -0,0 +1,63 @@
+/*
+ * To change this license header, choose License Headers in Project Properties.
+ * To change this template file, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package org.anarres.cpp;
+
+import com.google.common.io.CharStreams;
+import java.io.IOException;
+import java.io.Reader;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import static org.junit.Assert.*;
+
+/**
+ *
+ * @author shevek
+ */
+public class VaArgsPastingTest {
+
+ private static final Logger LOG = LoggerFactory.getLogger(VaArgsPastingTest.class);
+
+ @Test
+ public void testWhitespacePasting() throws IOException {
+ String input
+ = "#define REGULAR_ARGS(x, y) foo(x, y)\n"
+ + "#define REGULAR_ELLIPSIS(x, y...) foo(x, y)\n"
+ + "#define REGULAR_VAARGS(x, ...) foo(x, __VA_ARGS__)\n"
+ + "#define PASTE_ARGS(x, y) foo(x, ## y)\n"
+ + "#define PASTE_ELLIPSIS(x, y...) foo(x, ## y)\n"
+ + "#define PASTE_VAARGS(x, ...) foo(x, ## __VA_ARGS__)\n"
+ + ""
+ + "REGULAR_ARGS(a, b) // REGULAR_ARGS 2\n"
+ + "REGULAR_ELLIPSIS(a, b) // REGULAR_ELLIPSIS 2\n"
+ + "REGULAR_ELLIPSIS(a) // REGULAR_ELLIPSIS 1\n"
+ + "REGULAR_VAARGS(a, b) // REGULAR_VAARGS 2\n"
+ + "REGULAR_VAARGS(a) // REGULAR_VAARGS 1\n"
+ + ""
+ + "PASTE_ARGS(a, b) // PASTE_ARGS 2\n"
+ + "PASTE_ELLIPSIS(a, b) // PASTE_ELLIPSIS 2\n"
+ + "PASTE_ELLIPSIS(a) // PASTE_ELLIPSIS 1\n"
+ + "PASTE_VAARGS(a, b) // PASTE_VAARGS 2\n"
+ + "PASTE_VAARGS(a) // PASTE_VAARGS 1\n";
+ LOG.info("Input is:\n" + input);
+ Preprocessor pp = new Preprocessor();
+ pp.addFeature(Feature.KEEPCOMMENTS);
+ pp.addInput(new StringLexerSource(input, true));
+ Reader r = new CppReader(pp);
+ String output = CharStreams.toString(r).trim();
+ LOG.info("Output is:\n" + output);
+ assertEquals("foo(a, b) // REGULAR_ARGS 2\n"
+ + "foo(a, b) // REGULAR_ELLIPSIS 2\n"
+ + "foo(a, ) // REGULAR_ELLIPSIS 1\n"
+ + "foo(a, b) // REGULAR_VAARGS 2\n"
+ + "foo(a, ) // REGULAR_VAARGS 1\n"
+ + "foo(a,b) // PASTE_ARGS 2\n" // cpp outputs a warning and a space after the comma, similar below.
+ + "foo(a,b) // PASTE_ELLIPSIS 2\n"
+ + "foo(a) // PASTE_ELLIPSIS 1\n"
+ + "foo(a,b) // PASTE_VAARGS 2\n"
+ + "foo(a) // PASTE_VAARGS 1\n", output);
+ }
+}