cue/scanner: added fuzzing code

Running this trough the fuzzer did not yield any
crashers.

Change-Id: I723e66c96b33fc38e2ac069800ce8da9c56fc99f
Reviewed-on: https://cue-review.googlesource.com/c/cue/+/2623
Reviewed-by: Marcel van Lohuizen <mpvl@google.com>
diff --git a/cue/scanner/corpus/+basic.cue b/cue/scanner/corpus/+basic.cue
new file mode 100644
index 0000000..fb0e422
--- /dev/null
+++ b/cue/scanner/corpus/+basic.cue
@@ -0,0 +1,58 @@
+/* a comment */
+/*
+*/
+@foo()
+@foo(,,)
+@foo(a)
+@foo(aa=b)
+@foo(,a=b)
+@foo(",a=b")
+@foo(##"\(),a=b"##)
+@foo("",a="")
+_|_
+foobar
+a۰۱۸
+foo६४
+bar9876

+ŝfoo
+0
+1
+123456789012345678890
+12345_67890_12345_6788_90
+1234567M
+1234567Mi
+1234567
+.3Mi
+3.3Mi
+0xcafebabe
+0b1100_1001
+0o1234567
+0.
+.0
+3.14159265
+1e0
+1e+100
+1e-100
+2.71828e-1000
+'a'
+'\\000'
+'\\xFF'
+'\\uff16'
+'\\uD801'
+'\\U0000ff16'
+'foobar'
+'foo\/bar'
+#" ""#
+#"foobar"#
+#"\r"#
+#"\("#
+#"\q"#
+###"\##q"###
+"foobar"
+"""
+  foobar
+  """
+#"""
+  \(foobar
+  """#
diff --git a/cue/scanner/corpus/+comments.cue b/cue/scanner/corpus/+comments.cue
new file mode 100644
index 0000000..e924b70
--- /dev/null
+++ b/cue/scanner/corpus/+comments.cue
@@ -0,0 +1,24 @@
+foo //comment
+foo //comment
+foo /*comment*/
+foo /*\n*/
+foo /*comment*/
+foo /*
+*/
+
+foo // comment
+foo /*comment*/
+foo /*
+*/
+foo /*  */ /*
+ */, bar /**/
+foo /*0*/ /*1*/ /*2*/
+
+foo /*comment*/
+foo /*0*/ /*1*/ /*2*/
+foo /**/ /*-------------*/ /*----
+*/, bar /*
+baa
+foo    /* an EOF terminates a line */
+foo /* an EOF terminates a line */ /*
+foo    /* an EOF terminates a line */ //
diff --git a/cue/scanner/corpus/+package.cue b/cue/scanner/corpus/+package.cue
new file mode 100644
index 0000000..06ab7d0
--- /dev/null
+++ b/cue/scanner/corpus/+package.cue
@@ -0,0 +1 @@
+package main
diff --git a/cue/scanner/corpus/+tokens.cue b/cue/scanner/corpus/+tokens.cue
new file mode 100644
index 0000000..66191b0
--- /dev/null
+++ b/cue/scanner/corpus/+tokens.cue
@@ -0,0 +1,49 @@
+\ufeff
+,
+foo
+_foo
+123
+1.2
+'x'
+_|_
+"x"
+#'x'#
+	"""
+		foo
+	""
++-*/%
+&|
+&&
+||
+<-
+->
+==
+<
+>
+=
+!
+!=
+<=
+>=
+:=
+...
+(
+[
+[[
+{
+{{
+.
+)
+]
+]]
+}
+}}
+:
+;
+true
+false
+null
+for
+if
+let
+in
\ No newline at end of file
diff --git a/cue/scanner/fuzz.go b/cue/scanner/fuzz.go
new file mode 100644
index 0000000..68a894a
--- /dev/null
+++ b/cue/scanner/fuzz.go
@@ -0,0 +1,39 @@
+// Copyright 2019 CUE Authors
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+// +build gofuzz
+
+package scanner
+
+import (
+	"cuelang.org/go/cue/token"
+)
+
+func Fuzz(b []byte) int {
+	retCode := 1
+	eh := func(_ token.Pos, msg string, args []interface{}) {
+		retCode = 0
+	}
+
+	var s Scanner
+	s.Init(token.NewFile("", 1, len(b)), b, eh, ScanComments)
+
+	for {
+		_, tok, _ := s.Scan()
+		if tok == token.EOF {
+			break
+		}
+	}
+	return retCode
+}