-
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.
- Loading branch information
1 parent
54ff075
commit 4853238
Showing
7 changed files
with
219 additions
and
11 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`handles nested arrays with inlineArrayLimit 1`] = ` | ||
"{ | ||
matrix: [[1, 2], [3, 4]] | ||
}" | ||
`; | ||
|
||
exports[`serializes arrays with newlines when length exceeds the inlineArrayLimit with space set 1`] = ` | ||
"{ | ||
numbers: [ | ||
1, | ||
2, | ||
3, | ||
4, | ||
5 | ||
] | ||
}" | ||
`; | ||
|
||
exports[`serializes arrays without newlines when length equals the inlineArrayLimit 1`] = ` | ||
"{ | ||
numbers: [1, 2, 3, 4, 5] | ||
}" | ||
`; | ||
|
||
exports[`serializes arrays without newlines when length exceeds the inlineArrayLimit 1`] = `"{numbers: [1, 2, 3, 4, 5]}"`; | ||
|
||
exports[`serializes arrays without newlines when length is below the inlineArrayLimit 1`] = `"{numbers: [1, 2, 3]}"`; |
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,3 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`handles strings with newlines and other special chars 1`] = `"{title: 'AIOZ Network is a DePIN for Web3 AI, Storage and Streaming.\\n\\nAIOZ empowers a faster, secure and decentralized future.\\n\\nPowered by a global network of DePINs, AIOZ rewards you for sharing your computational resources for storing, transcoding, and streaming digital media content and powering decentralized AI computation.', description: 'AIOZ Network is a DePIN for Web3 AI, Storage and Streaming.\\n\\t\\rAIOZ empowers a faster, secure and decentralized future.\\n\\nPowered by a global network of DePINs, AIOZ rewards you for sharing your computational resources for storing, transcoding, and streaming digital media content and powering decentralized AI computation.'}"`; |
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,61 @@ | ||
import { jsStringify } from '../src'; | ||
|
||
it('serializes arrays without newlines when length is below the inlineArrayLimit', () => { | ||
const obj = { | ||
numbers: [1, 2, 3] | ||
}; | ||
const options = { | ||
inlineArrayLimit: 3 | ||
}; | ||
const output = jsStringify(obj, options); | ||
expect(output).toMatchSnapshot(); | ||
}); | ||
|
||
it('serializes arrays without newlines when length exceeds the inlineArrayLimit', () => { | ||
const obj = { | ||
numbers: [1, 2, 3, 4, 5] | ||
}; | ||
const options = { | ||
inlineArrayLimit: 3 | ||
}; | ||
const output = jsStringify(obj, options); | ||
expect(output).toMatchSnapshot(); | ||
}); | ||
it('serializes arrays with newlines when length exceeds the inlineArrayLimit with space set', () => { | ||
const obj = { | ||
numbers: [1, 2, 3, 4, 5] | ||
}; | ||
const options = { | ||
inlineArrayLimit: 3, | ||
space: 2 | ||
}; | ||
const output = jsStringify(obj, options); | ||
expect(output).toMatchSnapshot(); | ||
}); | ||
|
||
it('serializes arrays without newlines when length equals the inlineArrayLimit', () => { | ||
const obj = { | ||
numbers: [1, 2, 3, 4, 5] | ||
}; | ||
const options = { | ||
inlineArrayLimit: 5, | ||
space: 2 | ||
}; | ||
const output = jsStringify(obj, options); | ||
expect(output).toMatchSnapshot(); | ||
}); | ||
|
||
it('handles nested arrays with inlineArrayLimit', () => { | ||
const obj = { | ||
matrix: [ | ||
[1, 2], | ||
[3, 4] | ||
] | ||
}; | ||
const options = { | ||
inlineArrayLimit: 2, // Applies to inner arrays | ||
space: 2 | ||
}; | ||
const output = jsStringify(obj, options); | ||
expect(output).toMatchSnapshot(); | ||
}); |
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,77 @@ | ||
import { jsStringify, chooseQuotes } from '../src'; | ||
|
||
it('handles strings with newlines and other special chars', () => { | ||
const obj = { | ||
"title": "AIOZ Network is a DePIN for Web3 AI, Storage and Streaming.\n\nAIOZ empowers a faster, secure and decentralized future.\n\nPowered by a global network of DePINs, AIOZ rewards you for sharing your computational resources for storing, transcoding, and streaming digital media content and powering decentralized AI computation.", | ||
"description": "AIOZ Network is a DePIN for Web3 AI, Storage and Streaming.\n\t\rAIOZ empowers a faster, secure and decentralized future.\n\nPowered by a global network of DePINs, AIOZ rewards you for sharing your computational resources for storing, transcoding, and streaming digital media content and powering decentralized AI computation." | ||
}; | ||
const options = {}; | ||
const output = jsStringify(obj, options); | ||
expect(output).toMatchSnapshot(); | ||
}); | ||
|
||
describe('chooseQuotes', () => { | ||
test('handles strings with no special characters using single quotes', () => { | ||
const str = "Hello world"; | ||
expect(chooseQuotes(str, 'single')).toBe("'Hello world'"); | ||
}); | ||
|
||
test('handles strings with no special characters using double quotes', () => { | ||
const str = "Hello world"; | ||
expect(chooseQuotes(str, 'double')).toBe('"Hello world"'); | ||
}); | ||
|
||
test('handles strings with no special characters using backticks', () => { | ||
const str = "Hello world"; | ||
expect(chooseQuotes(str, 'backtick')).toBe('`Hello world`'); | ||
}); | ||
|
||
test('handles strings with single quotes', () => { | ||
const str = "It's a sunny day"; | ||
expect(chooseQuotes(str, 'single')).toBe("'It\\'s a sunny day'"); | ||
expect(chooseQuotes(str, 'double')).toBe('"It\'s a sunny day"'); | ||
expect(chooseQuotes(str, 'backtick')).toBe('`It\'s a sunny day`'); | ||
}); | ||
|
||
test('handles strings with double quotes', () => { | ||
const str = 'She said, "Hello"'; | ||
expect(chooseQuotes(str, 'single')).toBe("'She said, \"Hello\"'"); | ||
expect(chooseQuotes(str, 'double')).toBe('"She said, \\"Hello\\""'); | ||
expect(chooseQuotes(str, 'backtick')).toBe('`She said, "Hello"`'); | ||
}); | ||
|
||
test('handles strings with backticks', () => { | ||
const str = '`Hello` world'; | ||
expect(chooseQuotes(str, 'single')).toBe("'`Hello` world'"); | ||
expect(chooseQuotes(str, 'double')).toBe('"`Hello` world"'); | ||
expect(chooseQuotes(str, 'backtick')).toBe('`\\`Hello\\` world`'); | ||
}); | ||
|
||
test('handles strings with single and double quotes', () => { | ||
const str = "It's a \"wonderful\" day"; | ||
expect(chooseQuotes(str, 'single')).toBe("'It\\'s a \"wonderful\" day'"); | ||
expect(chooseQuotes(str, 'double')).toBe('"It\'s a \\"wonderful\\" day"'); | ||
expect(chooseQuotes(str, 'backtick')).toBe('`It\'s a "wonderful" day`'); | ||
}); | ||
|
||
test('handles strings with single quotes and backticks', () => { | ||
const str = "It's `great`"; | ||
expect(chooseQuotes(str, 'single')).toBe("'It\\'s `great`'"); | ||
expect(chooseQuotes(str, 'double')).toBe('"It\'s `great`"'); | ||
expect(chooseQuotes(str, 'backtick')).toBe('`It\'s \\`great\\``'); | ||
}); | ||
|
||
test('handles strings with double quotes and backticks', () => { | ||
const str = "`Hello`, he said, \"Good morning!\""; | ||
expect(chooseQuotes(str, 'single')).toBe("'`Hello`, he said, \"Good morning!\"'"); | ||
expect(chooseQuotes(str, 'double')).toBe('"`Hello`, he said, \\"Good morning!\\""'); | ||
expect(chooseQuotes(str, 'backtick')).toBe('`\\`Hello\\`, he said, "Good morning!"`'); | ||
}); | ||
|
||
test('handles strings with all types of quotes', () => { | ||
const str = "It's `really` a \"wonderful\" day"; | ||
expect(chooseQuotes(str, 'single')).toBe("'It\\'s `really` a \"wonderful\" day'"); | ||
expect(chooseQuotes(str, 'double')).toBe('"It\'s `really` a \\"wonderful\\" day"'); | ||
expect(chooseQuotes(str, 'backtick')).toBe('`It\'s \\`really\\` a "wonderful" day`'); | ||
}); | ||
}); |
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