Skip to content

Commit

Permalink
Chore: Add typescript-specific edge case tests to space-infix-ops (#1…
Browse files Browse the repository at this point in the history
  • Loading branch information
madbence authored and not-an-aardvark committed Oct 16, 2018
1 parent d45b184 commit 577cbf1
Show file tree
Hide file tree
Showing 2 changed files with 159 additions and 1 deletion.
155 changes: 155 additions & 0 deletions tests/fixtures/parsers/typescript-parsers/type-alias.js
@@ -0,0 +1,155 @@
"use strict";

exports.parse = () => ({
type: "Program",
range: [0, 16],
loc: {
start: { line: 1, column: 0 },
end: { line: 1, column: 16 }
},
body: [
{
type: "VariableDeclaration",
range: [0, 16],
loc: {
start: { line: 1, column: 0 },
end: { line: 1, column: 16 }
},
kind: "type",
declarations: [
{
type: "VariableDeclarator",
id: {
type: "Identifier",
range: [
5,
8
],
loc: {
start: { line: 1, column: 5 },
end: { line: 1, column: 8 }
},
name: "Foo"
},
init: {
type: "TSTypeReference",
range: [14, 15],
loc: {
start: { line: 1, column: 14 },
end: { line: 1, column: 15 }
},
typeName: {
type: "Identifier",
range: [14, 15],
loc: {
start: { line: 1, column: 14 },
end: { line: 1, column: 15 }
},
name: "T"
}
},
range: [5, 16],
loc: {
start: { line: 1, column: 5 },
end: { line: 1, column: 16 }
},
typeParameters: {
type: "TSTypeParameterDeclaration",
range: [8, 11],
loc: {
start: { line: 1, column: 8 },
end: { line: 1, column: 11 }
},
params: [
{
type: "TSTypeParameter",
range: [9, 10],
loc: {
start: { line: 1, column: 9 },
end: { line: 1, column: 10 }
},
name: "T"
}
]
}
}
]
}
],
sourceType: "script",
tokens: [
{
type: "Identifier",
value: "type",
range: [0, 4],
loc: {
start: { line: 1, column: 0 },
end: { line: 1, column: 4 }
}
},
{
type: "Identifier",
value: "Foo",
range: [5, 8],
loc: {
start: { line: 1, column: 5 },
end: { line: 1, column: 8 }
}
},
{
type: "Punctuator",
value: "<",
range: [8, 9],
loc: {
start: { line: 1, column: 8 },
end: { line: 1, column: 9 }
}
},
{
type: "Identifier",
value: "T",
range: [9, 10],
loc: {
start: { line: 1, column: 9 },
end: { line: 1, column: 10 }
}
},
{
type: "Punctuator",
value: ">",
range: [10, 11],
loc: {
start: { line: 1, column: 10 },
end: { line: 1, column: 11 }
}
},
{
type: "Punctuator",
value: "=",
range: [12, 13],
loc: {
start: { line: 1, column: 12 },
end: { line: 1, column: 13 }
}
},
{
type: "Identifier",
value: "T",
range: [14, 15],
loc: {
start: { line: 1, column: 14 },
end: { line: 1, column: 15 }
}
},
{
type: "Punctuator",
value: ";",
range: [15, 16],
loc: {
start: { line: 1, column: 15 },
end: { line: 1, column: 16 }
}
}
],
comments: []
})
5 changes: 4 additions & 1 deletion tests/lib/rules/space-infix-ops.js
Expand Up @@ -44,7 +44,10 @@ ruleTester.run("space-infix-ops", rule, {
{ code: "function foo(a: number = 0) { }", parserOptions: { ecmaVersion: 6 }, parser: parser("type-annotations/function-parameter-type-annotation") },
{ code: "function foo(): Bar { }", parserOptions: { ecmaVersion: 6 }, parser: parser("type-annotations/function-return-type-annotation") },
{ code: "var foo: Bar = '';", parserOptions: { ecmaVersion: 6 }, parser: parser("type-annotations/variable-declaration-init-type-annotation") },
{ code: "const foo = function(a: number = 0): Bar { };", parserOptions: { ecmaVersion: 6 }, parser: parser("type-annotations/function-expression-type-annotation") }
{ code: "const foo = function(a: number = 0): Bar { };", parserOptions: { ecmaVersion: 6 }, parser: parser("type-annotations/function-expression-type-annotation") },

// TypeScript Type Aliases
{ code: "type Foo<T> = T;", parserOptions: { ecmaVersion: 6 }, parser: parser("typescript-parsers/type-alias") }
],
invalid: [
{
Expand Down

0 comments on commit 577cbf1

Please sign in to comment.