From fd2cda5113208d434b53f117d123e0e100e49670 Mon Sep 17 00:00:00 2001
From: Mark Laptop <mark.wheelhouse@imperial.ac.uk>
Date: Sat, 18 Jan 2020 21:45:34 +0000
Subject: [PATCH] added four new tests for string and char[] behaviour

---
 .../semanticErr/expressions/stringElemErr.wacc   | 16 ++++++++++++++++
 invalid/semanticErr/print/printTypeErr02.wacc    | 14 ++++++++++++++
 invalid/syntaxErr/print/printlnCharArry.wacc     | 13 +++++++++++++
 valid/IO/print/printCharArray.wacc               | 14 ++++++++++++++
 4 files changed, 57 insertions(+)
 create mode 100644 invalid/semanticErr/expressions/stringElemErr.wacc
 create mode 100644 invalid/semanticErr/print/printTypeErr02.wacc
 create mode 100644 invalid/syntaxErr/print/printlnCharArry.wacc
 create mode 100644 valid/IO/print/printCharArray.wacc

diff --git a/invalid/semanticErr/expressions/stringElemErr.wacc b/invalid/semanticErr/expressions/stringElemErr.wacc
new file mode 100644
index 0000000..b4102e6
--- /dev/null
+++ b/invalid/semanticErr/expressions/stringElemErr.wacc
@@ -0,0 +1,16 @@
+# element access is not permitted for strings
+
+# Output:
+# #semantic_error#
+
+# Exit:
+# 200
+
+# Program:
+
+begin
+  string str = "hello world!" ;
+  println str ;
+  str[0] = 'H' ;
+  println str
+end
diff --git a/invalid/semanticErr/print/printTypeErr02.wacc b/invalid/semanticErr/print/printTypeErr02.wacc
new file mode 100644
index 0000000..b05dead
--- /dev/null
+++ b/invalid/semanticErr/print/printTypeErr02.wacc
@@ -0,0 +1,14 @@
+# type mismatch: string <- char[]
+
+# Output:
+# #semantic_error#
+
+# Exit:
+# 200
+
+# Program:
+
+begin
+  string s = ['h','i','!'];
+  println s
+end
diff --git a/invalid/syntaxErr/print/printlnCharArry.wacc b/invalid/syntaxErr/print/printlnCharArry.wacc
new file mode 100644
index 0000000..5241c89
--- /dev/null
+++ b/invalid/syntaxErr/print/printlnCharArry.wacc
@@ -0,0 +1,13 @@
+# You cannot directly print a char[] in WACC
+
+# Output:
+# #syntax_error#
+
+# Exit:
+# 100
+
+# Program:
+
+begin
+  println ['H','e','l','l','o',' ','W','o','r','l','d','!']
+end
diff --git a/valid/IO/print/printCharArray.wacc b/valid/IO/print/printCharArray.wacc
new file mode 100644
index 0000000..49e312c
--- /dev/null
+++ b/valid/IO/print/printCharArray.wacc
@@ -0,0 +1,14 @@
+# printing the contents of a char[] is possible via an intermediate variable
+
+# Output:
+# hi!
+
+# Exit:
+# 0
+
+# Program:
+
+begin
+  char[] s = ['h','i','!'];
+  println s
+end
-- 
GitLab