summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorparksb <parkgds@gmail.com>2020-10-04 18:04:17 +0900
committerDavid Peter <sharkdp@users.noreply.github.com>2020-10-04 15:25:39 +0200
commiteb3e2dca2479f73d8d9a62070d9c95eb08d6bf6a (patch)
tree47ef21a0e632dcac57a7ee35f4afa97ce38ec773 /tests
parent2d9b936b0a60dd05b2234a3befbaaba34d08c2ad (diff)
Add basic typescript test file
Diffstat (limited to 'tests')
-rw-r--r--tests/syntax-tests/highlighted/TypeScript/example.ts110
-rw-r--r--tests/syntax-tests/source/TypeScript/LICENSE.md17
-rw-r--r--tests/syntax-tests/source/TypeScript/example.ts110
3 files changed, 237 insertions, 0 deletions
diff --git a/tests/syntax-tests/highlighted/TypeScript/example.ts b/tests/syntax-tests/highlighted/TypeScript/example.ts
new file mode 100644
index 00000000..951b8dd8
--- /dev/null
+++ b/tests/syntax-tests/highlighted/TypeScript/example.ts
@@ -0,0 +1,110 @@
+let letNumber = 10;
+const constNumber = 20;
+
+const bool: boolean = true;
+const list: number[] = [1, 2, 3];
+const array: Array<number> = [1, 2, 3];
+const pair: [string, number] = ['hello', 10];
+
+for (let i = 0; i < list.length; i += 1) {
+ console.log(list[i]);
+}
+
+if (bool) {
+ console.log('True');
+} else {
+ console.log('False');
+}
+
+const str: string = 'Jake';
+const templateStr: string = `Hello, ${str}!`;
+
+// A comment
+
+/*
+ * Multiline comments
+ * Multiline comments
+ */
+
+interface SquareConfig {
+ label: string;
+ color?: string;
+ width?: number;
+ [propName: string]: any;
+}
+
+interface SearchFunc {
+ (source: string, subString: string): boolean;
+}
+
+enum Color {
+ Red,
+ Green,
+}
+
+type Easing = "ease-in" | "ease-out" | "ease-in-out";
+
+class Greeter {
+ private readonly greeting: string;
+
+ constructor(message: string) {
+ this.greeting = message;
+ }
+
+ greet() {
+ return "Hello, " + this.greeting;
+ }
+}
+
+let greeter = new Greeter("world");
+
+class Animal {
+ move(distanceInMeters: number = 0) {
+ console.log(`Animal moved ${distanceInMeters}m.`);
+ }
+}
+
+class Dog extends Animal {
+ bark() {
+ console.log("Woof! Woof!");
+ }
+}
+
+const dog = new Dog();
+dog.bark();
+dog.move(10);
+dog.bark();
+
+class Point {
+ x: number;
+ y: number;
+}
+
+interface Point3d extends Point {
+ z: number;
+}
+
+let point3d: Point3d = { x: 1, y: 2, z: 3 };
+
+function add(x, y) {
+ return x + y;
+}
+
+let myAdd = function (x, y) {
+ return x + y;
+};
+
+(function () {
+ console.log('IIFE');
+}());
+
+function identity<T>(arg: T): T {
+ return arg;
+}
+
+let myIdentity: <T>(arg: T) => T = identity;
+
+class GenericNumber<T> {
+ zeroValue: T;
+ add: (x: T, y: T) => T;
+}
diff --git a/tests/syntax-tests/source/TypeScript/LICENSE.md b/tests/syntax-tests/source/TypeScript/LICENSE.md
new file mode 100644
index 00000000..9f2bf75b
--- /dev/null
+++ b/tests/syntax-tests/source/TypeScript/LICENSE.md
@@ -0,0 +1,17 @@
+The MIT License (MIT)
+Copyright (c) Microsoft Corporation
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
+associated documentation files (the "Software"), to deal in the Software without restriction,
+including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
+and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
+subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all copies or substantial
+portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
+NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
diff --git a/tests/syntax-tests/source/TypeScript/example.ts b/tests/syntax-tests/source/TypeScript/example.ts
new file mode 100644
index 00000000..548aa190
--- /dev/null
+++ b/tests/syntax-tests/source/TypeScript/example.ts
@@ -0,0 +1,110 @@
+let letNumber = 10;
+const constNumber = 20;
+
+const bool: boolean = true;
+const list: number[] = [1, 2, 3];
+const array: Array<number> = [1, 2, 3];
+const pair: [string, number] = ['hello', 10];
+
+for (let i = 0; i < list.length; i += 1) {
+ console.log(list[i]);
+}
+
+if (bool) {
+ console.log('True');
+} else {
+ console.log('False');
+}
+
+const str: string = 'Jake';
+const templateStr: string = `Hello, ${str}!`;
+
+// A comment
+
+/*
+ * Multiline comments
+ * Multiline comments
+ */
+
+interface SquareConfig {
+ label: string;
+ color?: string;
+ width?: number;
+ [propName: string]: any;
+}
+
+interface SearchFunc {
+ (source: string, subString: string): boolean;
+}
+
+enum Color {
+ Red,
+ Green,
+}
+
+type Easing = "ease-in" | "ease-out" | "ease-in-out";
+
+class Greeter {
+ private readonly greeting: string;
+
+ constructor(message: string) {
+ this.greeting = message;
+ }
+
+ greet() {
+ return "Hello, " + this.greeting;
+ }
+}
+
+let greeter = new Greeter("world");
+
+class Animal {
+ move(distanceInMeters: number = 0) {
+ console.log(`Animal moved ${distanceInMeters}m.`);
+ }
+}
+
+class Dog extends Animal {
+ bark() {
+ console.log("Woof! Woof!");
+ }
+}
+
+const dog = new Dog();
+dog.bark();
+dog.move(10);
+dog.bark();
+
+class Point {
+ x: number;
+ y: number;
+}
+
+interface Point3d extends Point {
+ z: number;
+}
+
+let point3d: Point3d = { x: 1, y: 2, z: 3 };
+
+function add(x, y) {
+ return x + y;
+}
+
+let myAdd = function (x, y) {
+ return x + y;
+};
+
+(function () {
+ console.log('IIFE');
+}());
+
+function identity<T>(arg: T): T {
+ return arg;
+}
+
+let myIdentity: <T>(arg: T) => T = identity;
+
+class GenericNumber<T> {
+ zeroValue: T;
+ add: (x: T, y: T) => T;
+}