Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve dedent (fixes #1202) #1203

Merged
merged 4 commits into from
Jan 18, 2018
Merged

Improve dedent (fixes #1202) #1203

merged 4 commits into from
Jan 18, 2018

Conversation

Cito
Copy link
Member

@Cito Cito commented Jan 11, 2018

As discussed in #1202, this changes the behavior of the dedent function that is used in unit tests to not return raw strings any more. Also added tests for the function itself.

Copy link
Contributor

@leebyron leebyron left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes sense to me - I agree that being explicit is better, though I prefer the String.raw approach discussed to avoid making the test cases harder to read.

@@ -190,7 +190,7 @@ describe('Printer: Query document', () => {

fragment frag on Friend {
foo(size: $size, bar: $b, obj: {key: "value", block: """
block string uses \"""
block string uses \\"""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of changing this to \\, could you use String.raw as discussed in #1202? This test case intends to show the actual GraphQL string written, so avoiding double-encoding is intentional.

@@ -212,7 +212,7 @@ describe('Type System Printer', () => {
}

type Root {
singleField(argOne: String = "tes\t de\fault"): String
singleField(argOne: String = "tes\\t de\\fault"): String
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same

@Cito
Copy link
Member Author

Cito commented Jan 12, 2018

That's true, using String.raw is clearer for the printer tests. I changed it and added another unit test to make sure interpolation also works properly when dedent is used as a string tag.

`).to.equal(
'type Query {\n me: User\n}\n\n' +
'type User {\n id: ID\n name: String\n}\n',
);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the current form, these tests are hard to read.
Would be great to have test string in a separate variable and expected string in readable form, e.g.:

const output = dedent`
  type Query {
    me: User
  }
`;

expect(output).to.equal([
  'type Query {',
  '  me: User',
  '}',
].join('\n'));

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that looks a bit nicer, particularly if you're using that style already elsewhere. I refactored it already.

@IvanGoncharov
Copy link
Member

@Cito Can you please rebase on top of 6f15123 ?

Changed the behavior of the function to not have the undocumented side
effect of converting the string to its escaped (raw) form any more,
and to also consider tabs in addition to spaces.

Also added unit tests for the dedent function and adapted existing
tests that were depending on the old behavior of the function.
@Cito
Copy link
Member Author

Cito commented Jan 12, 2018

Rebased onto current master now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants