aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Makefile46
-rw-r--r--loc.c2
-rw-r--r--tests/00
-rw-r--r--tests/11
-rw-r--r--tests/102
-rw-r--r--tests/111
-rw-r--r--tests/121
-rw-r--r--tests/132
-rw-r--r--tests/141
-rw-r--r--tests/151
-rw-r--r--tests/161
-rw-r--r--tests/171
-rw-r--r--tests/181
-rw-r--r--tests/191
-rw-r--r--tests/21
-rw-r--r--tests/201
-rw-r--r--tests/211
-rw-r--r--tests/221
-rw-r--r--tests/231
-rw-r--r--tests/241
-rw-r--r--tests/253
-rw-r--r--tests/263
-rw-r--r--tests/273
-rw-r--r--tests/283
-rw-r--r--tests/293
-rw-r--r--tests/33
-rw-r--r--tests/303
-rw-r--r--tests/313
-rw-r--r--tests/323
-rw-r--r--tests/333
-rw-r--r--tests/343
-rw-r--r--tests/353
-rw-r--r--tests/363
-rw-r--r--tests/371
-rw-r--r--tests/381
-rw-r--r--tests/391
-rw-r--r--tests/42
-rw-r--r--tests/52
-rw-r--r--tests/61
-rw-r--r--tests/71
-rw-r--r--tests/81
-rw-r--r--tests/92
42 files changed, 116 insertions, 2 deletions
diff --git a/Makefile b/Makefile
index 00e76ec..24417a8 100644
--- a/Makefile
+++ b/Makefile
@@ -9,8 +9,50 @@ loc.o: loc.c arg.h
loc: loc.o
$(CC) -o $@ loc.o $(LDFLAGS)
-check:
- true
+check: loc
+ test "$$(./loc < tests/0)" = 0
+ test "$$(./loc - < tests/0)" = 0
+ test "$$(./loc tests/1 tests/2 | sed 's/: */: /')" = "$$(printf '%s\n' 'tests/1: 0' 'tests/2: 1')"
+ test "$$(./loc tests/0)" = 0
+ test "$$(./loc tests/1)" = 0
+ test "$$(./loc tests/2)" = 1
+ test "$$(./loc tests/3)" = 0
+ test "$$(./loc tests/4)" = 2
+ test "$$(./loc tests/5)" = 2
+ test "$$(./loc tests/6)" = 1
+ test "$$(./loc tests/7)" = 0
+ test "$$(./loc tests/8)" = 1
+ test "$$(./loc tests/9)" = 1
+ test "$$(./loc tests/10)" = 2
+ test "$$(./loc tests/11)" = 0
+ test "$$(./loc tests/12)" = 1
+ test "$$(./loc tests/13)" = 2
+ test "$$(./loc tests/14)" = 1
+ test "$$(./loc tests/15)" = 0
+ test "$$(./loc tests/16)" = 0
+ test "$$(./loc tests/17)" = 1
+ test "$$(./loc tests/18)" = 0
+ test "$$(./loc tests/19)" = 1
+ test "$$(./loc tests/20)" = 1
+ test "$$(./loc tests/21)" = 1
+ test "$$(./loc tests/22)" = 1
+ test "$$(./loc tests/23)" = 1
+ test "$$(./loc tests/24)" = 1
+ test "$$(./loc tests/25)" = 0
+ test "$$(./loc tests/26)" = 3
+ test "$$(./loc tests/27)" = 3
+ test "$$(./loc tests/28)" = 3
+ test "$$(./loc tests/29)" = 3
+ test "$$(./loc tests/30)" = 1
+ test "$$(./loc tests/31)" = 1
+ test "$$(./loc tests/32)" = 1
+ test "$$(./loc tests/33)" = 1
+ test "$$(./loc tests/34)" = 2
+ test "$$(./loc tests/35)" = 2
+ test "$$(./loc tests/36)" = 2
+ test "$$(./loc tests/37)" = 1
+ test "$$(./loc tests/38)" = 0
+ test "$$(./loc tests/39)" = 1
install: loc
mkdir -p -- "$(DESTDIR)$(PREFIX)/bin/"
diff --git a/loc.c b/loc.c
index 4434a19..3f58bc9 100644
--- a/loc.c
+++ b/loc.c
@@ -52,6 +52,7 @@ count(int fd, const char *fname)
ret += (ssize_t)!beginning;
beginning = 1;
escaped = 0;
+ continue;
} else if (escaped) {
escaped = 0;
} else if (buf[i] == quote) {
@@ -59,6 +60,7 @@ count(int fd, const char *fname)
} else if (buf[i] == '\\') {
escaped = 1;
}
+ beginning = 0;
} else if (c_comment) {
if (buf[i] == '\n') {
ret += (ssize_t)!beginning;
diff --git a/tests/0 b/tests/0
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/tests/0
diff --git a/tests/1 b/tests/1
new file mode 100644
index 0000000..8b13789
--- /dev/null
+++ b/tests/1
@@ -0,0 +1 @@
+
diff --git a/tests/10 b/tests/10
new file mode 100644
index 0000000..a5b8098
--- /dev/null
+++ b/tests/10
@@ -0,0 +1,2 @@
+x//y
+z
diff --git a/tests/11 b/tests/11
new file mode 100644
index 0000000..b4d07ff
--- /dev/null
+++ b/tests/11
@@ -0,0 +1 @@
+/* x */
diff --git a/tests/12 b/tests/12
new file mode 100644
index 0000000..5d10bae
--- /dev/null
+++ b/tests/12
@@ -0,0 +1 @@
+x/* y */
diff --git a/tests/13 b/tests/13
new file mode 100644
index 0000000..54d7eb2
--- /dev/null
+++ b/tests/13
@@ -0,0 +1,2 @@
+x/* y */
+x
diff --git a/tests/14 b/tests/14
new file mode 100644
index 0000000..80d4ce8
--- /dev/null
+++ b/tests/14
@@ -0,0 +1 @@
+/* x */y
diff --git a/tests/15 b/tests/15
new file mode 100644
index 0000000..79beb60
--- /dev/null
+++ b/tests/15
@@ -0,0 +1 @@
+/* x *//* y */
diff --git a/tests/16 b/tests/16
new file mode 100644
index 0000000..ad5f298
--- /dev/null
+++ b/tests/16
@@ -0,0 +1 @@
+/*x*///y
diff --git a/tests/17 b/tests/17
new file mode 100644
index 0000000..67d8a7f
--- /dev/null
+++ b/tests/17
@@ -0,0 +1 @@
+/*x*//y
diff --git a/tests/18 b/tests/18
new file mode 100644
index 0000000..287548a
--- /dev/null
+++ b/tests/18
@@ -0,0 +1 @@
+/* x \*/
diff --git a/tests/19 b/tests/19
new file mode 100644
index 0000000..92272fb
--- /dev/null
+++ b/tests/19
@@ -0,0 +1 @@
+\/* x */
diff --git a/tests/2 b/tests/2
new file mode 100644
index 0000000..587be6b
--- /dev/null
+++ b/tests/2
@@ -0,0 +1 @@
+x
diff --git a/tests/20 b/tests/20
new file mode 100644
index 0000000..5b547a5
--- /dev/null
+++ b/tests/20
@@ -0,0 +1 @@
+\//
diff --git a/tests/21 b/tests/21
new file mode 100644
index 0000000..ecd2475
--- /dev/null
+++ b/tests/21
@@ -0,0 +1 @@
+\/ *
diff --git a/tests/22 b/tests/22
new file mode 100644
index 0000000..3acbcec
--- /dev/null
+++ b/tests/22
@@ -0,0 +1 @@
+/* x */ */
diff --git a/tests/23 b/tests/23
new file mode 100644
index 0000000..f714113
--- /dev/null
+++ b/tests/23
@@ -0,0 +1 @@
+/* x "*/" */
diff --git a/tests/24 b/tests/24
new file mode 100644
index 0000000..6cd8dff
--- /dev/null
+++ b/tests/24
@@ -0,0 +1 @@
+/* x '*/' */
diff --git a/tests/25 b/tests/25
new file mode 100644
index 0000000..9350792
--- /dev/null
+++ b/tests/25
@@ -0,0 +1,3 @@
+/*
+x
+*/
diff --git a/tests/26 b/tests/26
new file mode 100644
index 0000000..24f012c
--- /dev/null
+++ b/tests/26
@@ -0,0 +1,3 @@
+"/*
+x
+*/"
diff --git a/tests/27 b/tests/27
new file mode 100644
index 0000000..32dc19f
--- /dev/null
+++ b/tests/27
@@ -0,0 +1,3 @@
+'/*
+x
+*/'
diff --git a/tests/28 b/tests/28
new file mode 100644
index 0000000..43a0b9a
--- /dev/null
+++ b/tests/28
@@ -0,0 +1,3 @@
+"\"/*
+x
+*/
diff --git a/tests/29 b/tests/29
new file mode 100644
index 0000000..7dd24bf
--- /dev/null
+++ b/tests/29
@@ -0,0 +1,3 @@
+'\'/*
+x
+*/
diff --git a/tests/3 b/tests/3
new file mode 100644
index 0000000..06d5f3d
--- /dev/null
+++ b/tests/3
@@ -0,0 +1,3 @@
+ {}() [];
+
+;
diff --git a/tests/30 b/tests/30
new file mode 100644
index 0000000..c739847
--- /dev/null
+++ b/tests/30
@@ -0,0 +1,3 @@
+" "/*
+x
+*/
diff --git a/tests/31 b/tests/31
new file mode 100644
index 0000000..2ebd547
--- /dev/null
+++ b/tests/31
@@ -0,0 +1,3 @@
+' '/*
+x
+*/
diff --git a/tests/32 b/tests/32
new file mode 100644
index 0000000..8470c9c
--- /dev/null
+++ b/tests/32
@@ -0,0 +1,3 @@
+'"'/*
+x
+*/
diff --git a/tests/33 b/tests/33
new file mode 100644
index 0000000..8782f15
--- /dev/null
+++ b/tests/33
@@ -0,0 +1,3 @@
+"'"/*
+x
+*/
diff --git a/tests/34 b/tests/34
new file mode 100644
index 0000000..85bf9aa
--- /dev/null
+++ b/tests/34
@@ -0,0 +1,3 @@
+"
+
+"
diff --git a/tests/35 b/tests/35
new file mode 100644
index 0000000..8e38ed0
--- /dev/null
+++ b/tests/35
@@ -0,0 +1,3 @@
+'
+
+'
diff --git a/tests/36 b/tests/36
new file mode 100644
index 0000000..1e6f762
--- /dev/null
+++ b/tests/36
@@ -0,0 +1,3 @@
+x
+
+x
diff --git a/tests/37 b/tests/37
new file mode 100644
index 0000000..1bc266d
--- /dev/null
+++ b/tests/37
@@ -0,0 +1 @@
+/* // */ x
diff --git a/tests/38 b/tests/38
new file mode 100644
index 0000000..50da1b9
--- /dev/null
+++ b/tests/38
@@ -0,0 +1 @@
+// /* */ x
diff --git a/tests/39 b/tests/39
new file mode 100644
index 0000000..e5409e8
--- /dev/null
+++ b/tests/39
@@ -0,0 +1 @@
+/**//**/x
diff --git a/tests/4 b/tests/4
new file mode 100644
index 0000000..b77b4eb
--- /dev/null
+++ b/tests/4
@@ -0,0 +1,2 @@
+x
+y
diff --git a/tests/5 b/tests/5
new file mode 100644
index 0000000..d15422a
--- /dev/null
+++ b/tests/5
@@ -0,0 +1,2 @@
+x\
+y
diff --git a/tests/6 b/tests/6
new file mode 100644
index 0000000..c1b0730
--- /dev/null
+++ b/tests/6
@@ -0,0 +1 @@
+x \ No newline at end of file
diff --git a/tests/7 b/tests/7
new file mode 100644
index 0000000..83e9c4b
--- /dev/null
+++ b/tests/7
@@ -0,0 +1 @@
+//x
diff --git a/tests/8 b/tests/8
new file mode 100644
index 0000000..79f7cfe
--- /dev/null
+++ b/tests/8
@@ -0,0 +1 @@
+x//x
diff --git a/tests/9 b/tests/9
new file mode 100644
index 0000000..d1ed66e
--- /dev/null
+++ b/tests/9
@@ -0,0 +1,2 @@
+x//y\
+z