|
| 1 | +import { AttributeParser } from '../../parsers/AttributeParser'; |
| 2 | + |
| 3 | +describe('AttributeParser - Newline in description', () => { |
| 4 | + describe('Entity format', () => { |
| 5 | + it('should parse full description with newline characters for redirect_uri', () => { |
| 6 | + const content = ` |
| 7 | +### \`redirect_uri\` {{%deprecated%}} {#redirect_uri} |
| 8 | +
|
| 9 | +**Description:** The registered redirection URI(s) for the application stored as a single string. Multiple URIs are separated by whitespace characters. May contain \`\\n\` characters when multiple redirect URIs are registered.\\ |
| 10 | +**Type:** String\\ |
| 11 | +**Version history:**\\ |
| 12 | +0.0.0 - added\\ |
| 13 | +4.3.0 - deprecated in favour of [\`redirect_uris\`]({{< relref "entities/Application#redirect_uris" >}}), since the value of this property is not a well-formed URI when multiple redirect URIs are registered |
| 14 | +`; |
| 15 | + |
| 16 | + const attributes = AttributeParser.parseAttributesFromSection(content); |
| 17 | + |
| 18 | + expect(attributes).toHaveLength(1); |
| 19 | + expect(attributes[0].name).toBe('redirect_uri'); |
| 20 | + expect(attributes[0].description).toContain('May contain'); |
| 21 | + expect(attributes[0].description).toContain('\\n'); |
| 22 | + expect(attributes[0].description).toContain( |
| 23 | + 'characters when multiple redirect URIs are registered' |
| 24 | + ); |
| 25 | + expect(attributes[0].deprecated).toBe(true); |
| 26 | + }); |
| 27 | + |
| 28 | + it('should parse full description with multiline content', () => { |
| 29 | + const content = ` |
| 30 | +### \`multiline_field\` {#multiline_field} |
| 31 | +
|
| 32 | +**Description:** This is a description that spans |
| 33 | +multiple lines and should be captured |
| 34 | +completely until the Type section.\\ |
| 35 | +**Type:** String\\ |
| 36 | +**Version history:**\\ |
| 37 | +1.0.0 - added |
| 38 | +`; |
| 39 | + |
| 40 | + const attributes = AttributeParser.parseAttributesFromSection(content); |
| 41 | + |
| 42 | + expect(attributes).toHaveLength(1); |
| 43 | + expect(attributes[0].name).toBe('multiline_field'); |
| 44 | + expect(attributes[0].description).toContain( |
| 45 | + 'This is a description that spans' |
| 46 | + ); |
| 47 | + expect(attributes[0].description).toContain( |
| 48 | + 'multiple lines and should be captured' |
| 49 | + ); |
| 50 | + expect(attributes[0].description).toContain( |
| 51 | + 'completely until the Type section' |
| 52 | + ); |
| 53 | + }); |
| 54 | + }); |
| 55 | + |
| 56 | + describe('Method entity format', () => { |
| 57 | + it('should parse full description with newline characters in method entities', () => { |
| 58 | + const content = ` |
| 59 | +#### \`redirect_uri\` {{%deprecated%}} {#redirect_uri} |
| 60 | +
|
| 61 | +**Description:** The registered redirection URI(s) for the application stored as a single string. Multiple URIs are separated by whitespace characters. May contain \`\\n\` characters when multiple redirect URIs are registered.\\ |
| 62 | +**Type:** String\\ |
| 63 | +**Version history:**\\ |
| 64 | +0.0.0 - added\\ |
| 65 | +4.3.0 - deprecated |
| 66 | +`; |
| 67 | + |
| 68 | + const attributes = AttributeParser.parseMethodEntityAttributes(content); |
| 69 | + |
| 70 | + expect(attributes).toHaveLength(1); |
| 71 | + expect(attributes[0].name).toBe('redirect_uri'); |
| 72 | + expect(attributes[0].description).toContain('May contain'); |
| 73 | + expect(attributes[0].description).toContain('\\n'); |
| 74 | + expect(attributes[0].description).toContain( |
| 75 | + 'characters when multiple redirect URIs are registered' |
| 76 | + ); |
| 77 | + expect(attributes[0].deprecated).toBe(true); |
| 78 | + }); |
| 79 | + |
| 80 | + it('should parse full description with multiline content in method entities', () => { |
| 81 | + const content = ` |
| 82 | +#### \`multiline_field\` {#multiline_field} |
| 83 | +
|
| 84 | +**Description:** This is a description that spans |
| 85 | +multiple lines and should be captured |
| 86 | +completely until the Type section.\\ |
| 87 | +**Type:** String\\ |
| 88 | +**Version history:**\\ |
| 89 | +1.0.0 - added |
| 90 | +`; |
| 91 | + |
| 92 | + const attributes = AttributeParser.parseMethodEntityAttributes(content); |
| 93 | + |
| 94 | + expect(attributes).toHaveLength(1); |
| 95 | + expect(attributes[0].name).toBe('multiline_field'); |
| 96 | + expect(attributes[0].description).toContain( |
| 97 | + 'This is a description that spans' |
| 98 | + ); |
| 99 | + expect(attributes[0].description).toContain( |
| 100 | + 'multiple lines and should be captured' |
| 101 | + ); |
| 102 | + expect(attributes[0].description).toContain( |
| 103 | + 'completely until the Type section' |
| 104 | + ); |
| 105 | + }); |
| 106 | + }); |
| 107 | +}); |
0 commit comments