forked from facebook/relay
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Moved dedent helper from RelayTestUtils.js to dedent.js
Reviewed By: wincent Differential Revision: D3508229 fbshipit-source-id: d7986d86d09cc7ff18e5b9bf33d540a5f366ae77
- Loading branch information
Showing
4 changed files
with
211 additions
and
182 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,158 @@ | ||
/** | ||
* Copyright (c) 2013-present, Facebook, Inc. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
* | ||
* @emails oncall+relay | ||
*/ | ||
|
||
'use strict'; | ||
|
||
jest.unmock('dedent'); | ||
|
||
const dedent = require('dedent'); | ||
|
||
describe('dedent()', () => { | ||
describe('with an empty string', () => { | ||
it('does nothing', () => { | ||
expect(dedent('')).toBe(''); | ||
}); | ||
|
||
it('does not pad a blank line', () => { | ||
expect(dedent('', ' ')).toBe(''); | ||
}); | ||
}); | ||
|
||
describe('with a blank string', () => { | ||
it('strips the entire string', () => { | ||
expect(dedent(' ')).toBe(''); | ||
}); | ||
|
||
it('does not pad a blank line', () => { | ||
expect(dedent(' ', ' ')).toBe(''); | ||
}); | ||
}); | ||
|
||
describe('with a simple string', () => { | ||
it('does nothing when there is no indent', () => { | ||
expect(dedent('foo')).toBe('foo'); | ||
}); | ||
|
||
it('strips a leading indent', () => { | ||
expect(dedent(' foo')).toBe('foo'); | ||
}); | ||
|
||
it('applies a custom padding if requested', () => { | ||
expect(dedent(' foo', ' ')).toBe(' foo'); | ||
}); | ||
|
||
it('does nothing to trailing whitespace', () => { | ||
expect(dedent('foo ')).toBe('foo '); | ||
expect(dedent('foo ', ' ')).toBe(' foo '); | ||
}); | ||
}); | ||
|
||
describe('with a multiline string', () => { | ||
it('dedents based on the leading whitespace', () => { | ||
const string = ` | ||
query MyQuery { | ||
example { | ||
text | ||
} | ||
} | ||
`; | ||
expect(dedent(string)).toBe( | ||
'query MyQuery {\n' + | ||
' example {\n' + | ||
' text\n' + | ||
' }\n' + | ||
'}' | ||
); | ||
}); | ||
|
||
it('applies a custom padding if requested', () => { | ||
const string = ` | ||
query MyQuery { | ||
example { | ||
text | ||
} | ||
} | ||
`; | ||
expect(dedent(string, ' ')).toBe( | ||
' query MyQuery {\n' + | ||
' example {\n' + | ||
' text\n' + | ||
' }\n' + | ||
' }' | ||
); | ||
}); | ||
|
||
it('is deals with zero-width lines', () => { | ||
const string = ` | ||
query MyQuery { | ||
example { | ||
text | ||
} | ||
more | ||
} | ||
`; | ||
expect(dedent(string)).toBe( | ||
'query MyQuery {\n' + | ||
' example {\n' + | ||
' text\n' + | ||
' }\n' + | ||
'\n' + | ||
' more\n' + | ||
'}' | ||
); | ||
}); | ||
|
||
it('does not insert entirely blank lines when applying padding', () => { | ||
const string = ` | ||
query MyQuery { | ||
example { | ||
text | ||
} | ||
more | ||
} | ||
`; | ||
expect(dedent(string, ' ')).toBe( | ||
' query MyQuery {\n' + | ||
' example {\n' + | ||
' text\n' + | ||
' }\n' + | ||
'\n' + | ||
' more\n' + | ||
' }' | ||
); | ||
}); | ||
|
||
it('suppresses blank lines in the output', () => { | ||
/* eslint-disable no-trailing-spaces */ | ||
const string = ` | ||
query MyQuery { | ||
example { | ||
text | ||
} | ||
more | ||
} | ||
`; | ||
/* eslint-enable no-trailing-spaces */ | ||
expect(dedent(string, ' ')).toBe( | ||
' query MyQuery {\n' + | ||
' example {\n' + | ||
' text\n' + | ||
' }\n' + | ||
'\n' + | ||
' more\n' + | ||
' }' | ||
); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.