|
| 1 | +import { jsStringify, chooseQuotes } from '../src'; |
| 2 | + |
| 3 | +it('handles strings with newlines and other special chars', () => { |
| 4 | + const obj = { |
| 5 | + "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.", |
| 6 | + "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." |
| 7 | + }; |
| 8 | + const options = {}; |
| 9 | + const output = jsStringify(obj, options); |
| 10 | + expect(output).toMatchSnapshot(); |
| 11 | +}); |
| 12 | + |
| 13 | +describe('chooseQuotes', () => { |
| 14 | + test('handles strings with no special characters using single quotes', () => { |
| 15 | + const str = "Hello world"; |
| 16 | + expect(chooseQuotes(str, 'single')).toBe("'Hello world'"); |
| 17 | + }); |
| 18 | + |
| 19 | + test('handles strings with no special characters using double quotes', () => { |
| 20 | + const str = "Hello world"; |
| 21 | + expect(chooseQuotes(str, 'double')).toBe('"Hello world"'); |
| 22 | + }); |
| 23 | + |
| 24 | + test('handles strings with no special characters using backticks', () => { |
| 25 | + const str = "Hello world"; |
| 26 | + expect(chooseQuotes(str, 'backtick')).toBe('`Hello world`'); |
| 27 | + }); |
| 28 | + |
| 29 | + test('handles strings with single quotes', () => { |
| 30 | + const str = "It's a sunny day"; |
| 31 | + expect(chooseQuotes(str, 'single')).toBe("'It\\'s a sunny day'"); |
| 32 | + expect(chooseQuotes(str, 'double')).toBe('"It\'s a sunny day"'); |
| 33 | + expect(chooseQuotes(str, 'backtick')).toBe('`It\'s a sunny day`'); |
| 34 | + }); |
| 35 | + |
| 36 | + test('handles strings with double quotes', () => { |
| 37 | + const str = 'She said, "Hello"'; |
| 38 | + expect(chooseQuotes(str, 'single')).toBe("'She said, \"Hello\"'"); |
| 39 | + expect(chooseQuotes(str, 'double')).toBe('"She said, \\"Hello\\""'); |
| 40 | + expect(chooseQuotes(str, 'backtick')).toBe('`She said, "Hello"`'); |
| 41 | + }); |
| 42 | + |
| 43 | + test('handles strings with backticks', () => { |
| 44 | + const str = '`Hello` world'; |
| 45 | + expect(chooseQuotes(str, 'single')).toBe("'`Hello` world'"); |
| 46 | + expect(chooseQuotes(str, 'double')).toBe('"`Hello` world"'); |
| 47 | + expect(chooseQuotes(str, 'backtick')).toBe('`\\`Hello\\` world`'); |
| 48 | + }); |
| 49 | + |
| 50 | + test('handles strings with single and double quotes', () => { |
| 51 | + const str = "It's a \"wonderful\" day"; |
| 52 | + expect(chooseQuotes(str, 'single')).toBe("'It\\'s a \"wonderful\" day'"); |
| 53 | + expect(chooseQuotes(str, 'double')).toBe('"It\'s a \\"wonderful\\" day"'); |
| 54 | + expect(chooseQuotes(str, 'backtick')).toBe('`It\'s a "wonderful" day`'); |
| 55 | + }); |
| 56 | + |
| 57 | + test('handles strings with single quotes and backticks', () => { |
| 58 | + const str = "It's `great`"; |
| 59 | + expect(chooseQuotes(str, 'single')).toBe("'It\\'s `great`'"); |
| 60 | + expect(chooseQuotes(str, 'double')).toBe('"It\'s `great`"'); |
| 61 | + expect(chooseQuotes(str, 'backtick')).toBe('`It\'s \\`great\\``'); |
| 62 | + }); |
| 63 | + |
| 64 | + test('handles strings with double quotes and backticks', () => { |
| 65 | + const str = "`Hello`, he said, \"Good morning!\""; |
| 66 | + expect(chooseQuotes(str, 'single')).toBe("'`Hello`, he said, \"Good morning!\"'"); |
| 67 | + expect(chooseQuotes(str, 'double')).toBe('"`Hello`, he said, \\"Good morning!\\""'); |
| 68 | + expect(chooseQuotes(str, 'backtick')).toBe('`\\`Hello\\`, he said, "Good morning!"`'); |
| 69 | + }); |
| 70 | + |
| 71 | + test('handles strings with all types of quotes', () => { |
| 72 | + const str = "It's `really` a \"wonderful\" day"; |
| 73 | + expect(chooseQuotes(str, 'single')).toBe("'It\\'s `really` a \"wonderful\" day'"); |
| 74 | + expect(chooseQuotes(str, 'double')).toBe('"It\'s `really` a \\"wonderful\\" day"'); |
| 75 | + expect(chooseQuotes(str, 'backtick')).toBe('`It\'s \\`really\\` a "wonderful" day`'); |
| 76 | + }); |
| 77 | +}); |
0 commit comments