Skip to content

Commit 589db58

Browse files
committed
Unify 'printBlockString' tests in correct place
1 parent af9ba5a commit 589db58

File tree

3 files changed

+49
-89
lines changed

3 files changed

+49
-89
lines changed

src/language/__tests__/blockString-test.js

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
import { expect } from 'chai';
1111
import { describe, it } from 'mocha';
12-
import { dedentBlockStringValue } from '../blockString';
12+
import { dedentBlockStringValue, printBlockString } from '../blockString';
1313

1414
function joinLines(...args) {
1515
return args.join('\n');
@@ -98,3 +98,51 @@ describe('dedentBlockStringValue', () => {
9898
);
9999
});
100100
});
101+
102+
describe('printBlockString', () => {
103+
it('by default print block strings as single line', () => {
104+
const str = 'one liner';
105+
expect(printBlockString(str)).to.equal('"""one liner"""');
106+
expect(printBlockString(str, '', true)).to.equal('"""\none liner\n"""');
107+
});
108+
109+
it('correctly prints single-line with leading space', () => {
110+
const str = ' space-led string';
111+
expect(printBlockString(str)).to.equal('""" space-led string"""');
112+
expect(printBlockString(str, '', true)).to.equal(
113+
'""" space-led string\n"""',
114+
);
115+
});
116+
117+
it('correctly prints single-line with leading space and quotation', () => {
118+
const str = ' space-led value "quoted string"';
119+
120+
expect(printBlockString(str)).to.equal(
121+
'""" space-led value "quoted string"\n"""',
122+
);
123+
124+
expect(printBlockString(str, '', true)).to.equal(
125+
'""" space-led value "quoted string"\n"""',
126+
);
127+
});
128+
129+
it('correctly prints string with a first line indentation', () => {
130+
const str = joinLines(
131+
' first ',
132+
' line ',
133+
'indentation',
134+
' string',
135+
);
136+
137+
expect(printBlockString(str)).to.equal(
138+
joinLines(
139+
'"""',
140+
' first ',
141+
' line ',
142+
'indentation',
143+
' string',
144+
'"""',
145+
),
146+
);
147+
});
148+
});

src/language/__tests__/printer-test.js

Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -98,55 +98,6 @@ describe('Printer: Query document', () => {
9898
`);
9999
});
100100

101-
describe('block string', () => {
102-
it('correctly prints single-line with leading space', () => {
103-
const mutationASTWithArtifacts = parse(
104-
'{ field(arg: """ space-led value""") }',
105-
);
106-
expect(print(mutationASTWithArtifacts)).to.equal(dedent`
107-
{
108-
field(arg: """ space-led value""")
109-
}
110-
`);
111-
});
112-
113-
it('correctly prints string with a first line indentation', () => {
114-
const mutationASTWithArtifacts = parse(`
115-
{
116-
field(arg: """
117-
first
118-
line
119-
indentation
120-
""")
121-
}
122-
`);
123-
expect(print(mutationASTWithArtifacts)).to.equal(dedent`
124-
{
125-
field(arg: """
126-
first
127-
line
128-
indentation
129-
""")
130-
}
131-
`);
132-
});
133-
134-
it('correctly prints single-line with leading space and quotation', () => {
135-
const mutationASTWithArtifacts = parse(`
136-
{
137-
field(arg: """ space-led value "quoted string"
138-
""")
139-
}
140-
`);
141-
expect(print(mutationASTWithArtifacts)).to.equal(dedent`
142-
{
143-
field(arg: """ space-led value "quoted string"
144-
""")
145-
}
146-
`);
147-
});
148-
});
149-
150101
it('Experimental: correctly prints fragment defined variables', () => {
151102
const fragmentWithVariable = parse(
152103
`

src/utilities/__tests__/schemaPrinter-test.js

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -494,45 +494,6 @@ describe('Type System Printer', () => {
494494
expect(recreatedField).to.include({ description });
495495
});
496496

497-
it('Does not one-line print a description that ends with a quote', () => {
498-
const description = 'This field is "awesome"';
499-
const output = printSingleFieldSchema({
500-
type: GraphQLString,
501-
description,
502-
});
503-
expect(output).to.equal(dedent`
504-
type Query {
505-
"""
506-
This field is "awesome"
507-
"""
508-
singleField: String
509-
}
510-
`);
511-
const schema = buildSchema(output);
512-
const recreatedRoot = assertObjectType(schema.getTypeMap().Query);
513-
const recreatedField = recreatedRoot.getFields().singleField;
514-
expect(recreatedField).to.include({ description });
515-
});
516-
517-
it('Preserves leading spaces when printing a description', () => {
518-
const description = ' This field is "awesome"';
519-
const output = printSingleFieldSchema({
520-
type: GraphQLString,
521-
description,
522-
});
523-
expect(output).to.equal(dedent`
524-
type Query {
525-
""" This field is "awesome"
526-
"""
527-
singleField: String
528-
}
529-
`);
530-
const schema = buildSchema(output);
531-
const recreatedRoot = assertObjectType(schema.getTypeMap().Query);
532-
const recreatedField = recreatedRoot.getFields().singleField;
533-
expect(recreatedField).to.include({ description });
534-
});
535-
536497
it('Print Introspection Schema', () => {
537498
const Schema = new GraphQLSchema({});
538499
const output = printIntrospectionSchema(Schema);

0 commit comments

Comments
 (0)