summaryrefslogtreecommitdiff
path: root/tests/typ/code
diff options
context:
space:
mode:
authorMartin Haug <mhaug@live.de>2021-05-31 17:19:46 +0200
committerLaurenz <laurmaedje@gmail.com>2021-05-31 22:33:40 +0200
commit37e08460377498165f421a522cb4eb1bb4e246b7 (patch)
tree0480965d5497721db1f97d83057902fc2e2e719e /tests/typ/code
parent00ac68b8451179468aa39cba0d7fbea1ee20e0a1 (diff)
Test cases for include and import
Diffstat (limited to 'tests/typ/code')
-rw-r--r--tests/typ/code/block-scoping.typ10
-rw-r--r--tests/typ/code/import.typ119
-rw-r--r--tests/typ/code/importable/chap1.typ9
-rw-r--r--tests/typ/code/importable/chap2.typ11
-rw-r--r--tests/typ/code/importable/cycle1.typ7
-rw-r--r--tests/typ/code/importable/cycle2.typ7
-rw-r--r--tests/typ/code/include.typ23
-rw-r--r--tests/typ/code/target.typ12
8 files changed, 198 insertions, 0 deletions
diff --git a/tests/typ/code/block-scoping.typ b/tests/typ/code/block-scoping.typ
index 7bb98969..ed689f3d 100644
--- a/tests/typ/code/block-scoping.typ
+++ b/tests/typ/code/block-scoping.typ
@@ -19,6 +19,16 @@
{b}
---
+// Double block creates a scope.
+{{
+ import "target.typ" using b
+ test(b, 1)
+}}
+
+// Error: 2-3 unknown variable
+{b}
+
+---
// Multiple nested scopes.
{
let a = "a1"
diff --git a/tests/typ/code/import.typ b/tests/typ/code/import.typ
new file mode 100644
index 00000000..30dc556c
--- /dev/null
+++ b/tests/typ/code/import.typ
@@ -0,0 +1,119 @@
+// Test import statements.
+
+---
+// Test importing semantics.
+
+// A named import.
+#import "target.typ" using item
+#test(item(1, 2), 3)
+
+// Test that this will be overwritten.
+#let value = [foo]
+
+// Import multiple things.
+// Error: 28-29 expected expression, found comma
+#import "target.typ" using ,fn, value
+#fn[Like and Subscribe!]
+#value
+
+// Code mode
+{
+ import "target.typ" using b
+ test(b, 1)
+}
+
+#test(b, 1)
+
+// This should not exist yet
+// Error: 1-3 unknown variable
+#d
+
+// A wildcard import.
+#import "target.typ" using *
+
+// It exists now!
+#d
+
+---
+// Test bad imports.
+// Ref: false
+
+// Error: 9-11 file not found
+#import "" using name
+
+// Error: 9-20 file not found
+#import "lib/0.2.1" using *
+
+// Error: 9-20 file not found
+#import "lib@0.2.1" using *
+
+// Some non-text stuff.
+// Error: 9-30 file is not valid utf-8
+#import "../../res/rhino.png" using *
+
+// Unresolved import.
+// Error: 28-40 unresolved import
+#import "target.typ" using non_existing
+
+// Cyclic import.
+// Error: 9-34 cyclic import
+#import "./importable/cycle1.typ" using *
+
+---
+// Test syntax.
+
+// Missing file.
+// Error: 9-10 expected expression, found star
+#import *
+
+// Should output `"target.typ"`.
+// Error: 1-7 unexpected keyword `using`
+#using "target.typ"
+
+// Should output `target`.
+// Error: 3:9-4:8 file not found
+// Error: 3:8 expected semicolon or line break
+// Error: 2:8 expected keyword `using`
+#import "target.typ
+using "target
+
+// Should output `@ 0.2.1 using`.
+// Error: 2:21 expected semicolon or line break
+// Error: 1:21 expected keyword `using`
+#import "target.typ" @ 0.2.1 using *
+
+// Error: 3:21 expected keyword `using`
+// Error: 2:21 expected semicolon or line break
+// Error: 1:22-1:28 unexpected keyword `using`
+#import "target.typ" #using *
+
+// Error: 2:21 expected semicolon or line break
+// Error: 1:21 expected keyword `using`
+#import "target.typ" usinga,b,c
+
+// Error: 27 expected import items
+#import "target.typ" using
+
+// Error: 2:28-2:29 expected expression, found assignment operator
+// Error: 1:29 expected import items
+#import "target.typ" using =
+
+// Allow the trailing comma.
+#import "target.typ" using a, c,
+
+// An additional trailing comma.
+// Error: 36-37 expected expression, found comma
+#import "target.typ" using a, b, c,,
+
+// Star in the list.
+// Error: 2:31-2:32 expected expression, found star
+// Error: 32-33 expected expression, found comma
+#import "target.typ" using a, *, b
+
+// Stop at semicolon.
+#import "target.typ" using a, c;Hi
+
+// Who needs whitespace anyways?
+#import "target.typ"using *
+#import"target.typ"using*
+#import "target.typ"using *
diff --git a/tests/typ/code/importable/chap1.typ b/tests/typ/code/importable/chap1.typ
new file mode 100644
index 00000000..06a4c1a1
--- /dev/null
+++ b/tests/typ/code/importable/chap1.typ
@@ -0,0 +1,9 @@
+// Ref: false
+
+#let name = "Klaus"
+
+== Chapter 1
+#name stood in a field of wheat. There was nothing of particular interest about
+the field #name just casually surveyed for any paths on which the corn would not
+totally ruin his semi-new outdorsy jacket but then again, most of us spend
+considerable time in non-descript environments.
diff --git a/tests/typ/code/importable/chap2.typ b/tests/typ/code/importable/chap2.typ
new file mode 100644
index 00000000..d4aedc60
--- /dev/null
+++ b/tests/typ/code/importable/chap2.typ
@@ -0,0 +1,11 @@
+// Ref: false
+
+#let name = "Klaus"
+
+== Chapter 2
+Their motivations, however, were pretty descript, so to speak. #name had not yet
+conceptualized their consequences, but that should change pretty quickly. #name
+approached the center of the field and picked up a 4-foot long disk made from
+what could only be cow manure. The hair on the back of #name' neck bristled as
+he stared at the unusual sight. After studying the object for a while, he
+promptly popped the question, "How much?"
diff --git a/tests/typ/code/importable/cycle1.typ b/tests/typ/code/importable/cycle1.typ
new file mode 100644
index 00000000..e251686d
--- /dev/null
+++ b/tests/typ/code/importable/cycle1.typ
@@ -0,0 +1,7 @@
+// Ref: false
+
+// Error: 9-21 cyclic import
+#import "cycle2.typ" using *
+#let inaccessible = "wow"
+
+This is the first element of an import cycle.
diff --git a/tests/typ/code/importable/cycle2.typ b/tests/typ/code/importable/cycle2.typ
new file mode 100644
index 00000000..8071ec6b
--- /dev/null
+++ b/tests/typ/code/importable/cycle2.typ
@@ -0,0 +1,7 @@
+// Ref: false
+
+// Error: 9-21 cyclic import
+#import "cycle1.typ" using *
+#let val = "much cycle"
+
+This is the second element of an import cycle.
diff --git a/tests/typ/code/include.typ b/tests/typ/code/include.typ
new file mode 100644
index 00000000..9fd028f9
--- /dev/null
+++ b/tests/typ/code/include.typ
@@ -0,0 +1,23 @@
+// Test include statements.
+
+---
+= Document
+
+// Include a file
+#include "importable/chap1.typ"
+
+// The variables of the file should not appear in this scope.
+// Error: 1-6 unknown variable
+#name
+
+// Expression as a file name.
+#let chap2 = include "import" + "able/chap" + "2.typ"
+
+_ -- Intermission -- _
+#chap2
+
+{
+ // Expressions, code mode.
+ // Error: 21-43 file not found
+ let x = include "importable/chap3.typ"
+}
diff --git a/tests/typ/code/target.typ b/tests/typ/code/target.typ
new file mode 100644
index 00000000..12a5ff8b
--- /dev/null
+++ b/tests/typ/code/target.typ
@@ -0,0 +1,12 @@
+// A file to import in import / include tests.
+// Ref: false
+
+#let a
+#let b = 1
+#let c = 2
+#let d = 3
+#let value = [hi]
+#let item(a, b) = a + b
+#let fn(body) = rect(fill: conifer, pad(5pt, body))
+
+Some _includable_ text.