Skip to content

Commit 559b49b

Browse files
author
Andy Hanson
committed
Improve tests
1 parent 03371c0 commit 559b49b

8 files changed

Lines changed: 150 additions & 41 deletions

tests/baselines/reference/ambientDeclarationsPatterns.errors.txt

Lines changed: 0 additions & 29 deletions
This file was deleted.

tests/baselines/reference/ambientDeclarationsPatterns.js

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,21 @@
22

33
//// [declarations.d.ts]
44
declare module "foo*baz" {
5-
export function foo(n: number): void;
5+
export function foo(s: string): void;
66
}
77
// Augmentations still work
88
declare module "foo*baz" {
9-
export const baz: number;
9+
export const baz: string;
1010
}
1111

12-
// Should be an error
13-
declare module "too*many*asterisks" { }
14-
1512
// Longest prefix wins
1613
declare module "foos*" {
17-
export const foos: number;
14+
export const foos: string;
15+
}
16+
17+
declare module "*!text" {
18+
const x: string;
19+
export default x;
1820
}
1921

2022
//// [user.ts]
@@ -23,10 +25,20 @@ import {foo, baz} from "foobarbaz";
2325
foo(baz);
2426

2527
import {foos} from "foosball";
28+
foo(foos);
29+
30+
// Works with relative file name
31+
import fileText from "./file!text";
32+
foo(fileText);
2633

2734

2835
//// [user.js]
2936
"use strict";
3037
///<reference path="declarations.d.ts" />
3138
var foobarbaz_1 = require("foobarbaz");
3239
foobarbaz_1.foo(foobarbaz_1.baz);
40+
var foosball_1 = require("foosball");
41+
foobarbaz_1.foo(foosball_1.foos);
42+
// Works with relative file name
43+
var file_text_1 = require("./file!text");
44+
foobarbaz_1.foo(file_text_1["default"]);
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
=== tests/cases/conformance/ambient/user.ts ===
2+
///<reference path="declarations.d.ts" />
3+
import {foo, baz} from "foobarbaz";
4+
>foo : Symbol(foo, Decl(user.ts, 1, 8))
5+
>baz : Symbol(baz, Decl(user.ts, 1, 12))
6+
7+
foo(baz);
8+
>foo : Symbol(foo, Decl(user.ts, 1, 8))
9+
>baz : Symbol(baz, Decl(user.ts, 1, 12))
10+
11+
import {foos} from "foosball";
12+
>foos : Symbol(foos, Decl(user.ts, 4, 8))
13+
14+
foo(foos);
15+
>foo : Symbol(foo, Decl(user.ts, 1, 8))
16+
>foos : Symbol(foos, Decl(user.ts, 4, 8))
17+
18+
// Works with relative file name
19+
import fileText from "./file!text";
20+
>fileText : Symbol(fileText, Decl(user.ts, 8, 6))
21+
22+
foo(fileText);
23+
>foo : Symbol(foo, Decl(user.ts, 1, 8))
24+
>fileText : Symbol(fileText, Decl(user.ts, 8, 6))
25+
26+
=== tests/cases/conformance/ambient/declarations.d.ts ===
27+
declare module "foo*baz" {
28+
export function foo(s: string): void;
29+
>foo : Symbol(foo, Decl(declarations.d.ts, 0, 26))
30+
>s : Symbol(s, Decl(declarations.d.ts, 1, 24))
31+
}
32+
// Augmentations still work
33+
declare module "foo*baz" {
34+
export const baz: string;
35+
>baz : Symbol(baz, Decl(declarations.d.ts, 5, 16))
36+
}
37+
38+
// Longest prefix wins
39+
declare module "foos*" {
40+
export const foos: string;
41+
>foos : Symbol(foos, Decl(declarations.d.ts, 10, 16))
42+
}
43+
44+
declare module "*!text" {
45+
const x: string;
46+
>x : Symbol(x, Decl(declarations.d.ts, 14, 9))
47+
48+
export default x;
49+
>x : Symbol(x, Decl(declarations.d.ts, 14, 9))
50+
}
51+
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
=== tests/cases/conformance/ambient/user.ts ===
2+
///<reference path="declarations.d.ts" />
3+
import {foo, baz} from "foobarbaz";
4+
>foo : (s: string) => void
5+
>baz : string
6+
7+
foo(baz);
8+
>foo(baz) : void
9+
>foo : (s: string) => void
10+
>baz : string
11+
12+
import {foos} from "foosball";
13+
>foos : string
14+
15+
foo(foos);
16+
>foo(foos) : void
17+
>foo : (s: string) => void
18+
>foos : string
19+
20+
// Works with relative file name
21+
import fileText from "./file!text";
22+
>fileText : string
23+
24+
foo(fileText);
25+
>foo(fileText) : void
26+
>foo : (s: string) => void
27+
>fileText : string
28+
29+
=== tests/cases/conformance/ambient/declarations.d.ts ===
30+
declare module "foo*baz" {
31+
export function foo(s: string): void;
32+
>foo : (s: string) => void
33+
>s : string
34+
}
35+
// Augmentations still work
36+
declare module "foo*baz" {
37+
export const baz: string;
38+
>baz : string
39+
}
40+
41+
// Longest prefix wins
42+
declare module "foos*" {
43+
export const foos: string;
44+
>foos : string
45+
}
46+
47+
declare module "*!text" {
48+
const x: string;
49+
>x : string
50+
51+
export default x;
52+
>x : string
53+
}
54+
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
tests/cases/conformance/ambient/ambientDeclarationsPatterns_tooManyAsterisks.ts(1,16): error TS5061: Pattern 'too*many*asterisks' can have at most one '*' character
2+
3+
4+
==== tests/cases/conformance/ambient/ambientDeclarationsPatterns_tooManyAsterisks.ts (1 errors) ====
5+
declare module "too*many*asterisks" { }
6+
~~~~~~~~~~~~~~~~~~~~
7+
!!! error TS5061: Pattern 'too*many*asterisks' can have at most one '*' character
8+
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
//// [ambientDeclarationsPatterns_tooManyAsterisks.ts]
2+
declare module "too*many*asterisks" { }
3+
4+
5+
//// [ambientDeclarationsPatterns_tooManyAsterisks.js]
Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
// @Filename: declarations.d.ts
22
declare module "foo*baz" {
3-
export function foo(n: number): void;
3+
export function foo(s: string): void;
44
}
55
// Augmentations still work
66
declare module "foo*baz" {
7-
export const baz: number;
7+
export const baz: string;
88
}
99

10-
// Should be an error
11-
declare module "too*many*asterisks" { }
12-
1310
// Longest prefix wins
1411
declare module "foos*" {
15-
export const foos: number;
12+
export const foos: string;
13+
}
14+
15+
declare module "*!text" {
16+
const x: string;
17+
export default x;
1618
}
1719

1820
// @Filename: user.ts
@@ -21,3 +23,8 @@ import {foo, baz} from "foobarbaz";
2123
foo(baz);
2224

2325
import {foos} from "foosball";
26+
foo(foos);
27+
28+
// Works with relative file name
29+
import fileText from "./file!text";
30+
foo(fileText);
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
declare module "too*many*asterisks" { }

0 commit comments

Comments
 (0)