/
XSIFormatterLegacyTest.java
189 lines (177 loc) · 9.14 KB
/
XSIFormatterLegacyTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
/*******************************************************************************
* Copyright (c) 2020 Red Hat Inc. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v20.html
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Red Hat Inc. - initial API and implementation
*******************************************************************************/
package org.eclipse.lemminx.extensions.xsi;
import static org.eclipse.lemminx.XMLAssert.assertFormat;
import org.eclipse.lemminx.AbstractCacheBasedTest;
import org.eclipse.lemminx.commons.BadLocationException;
import org.eclipse.lemminx.extensions.xsi.settings.XSISchemaLocationSplit;
import org.eclipse.lemminx.settings.SharedSettings;
import org.eclipse.lemminx.settings.XMLFormattingOptions.SplitAttributes;
import org.junit.jupiter.api.Test;
/**
* XSI xsi:schemaLocation formatter tests for legacy formatter
*
*/
public class XSIFormatterLegacyTest extends AbstractCacheBasedTest {
@Test
public void xsiSchemaLocationSplitNone() throws BadLocationException {
// Default
SharedSettings settings = createSettings();
XSISchemaLocationSplit.setSplit(XSISchemaLocationSplit.none, settings.getFormattingSettings());
String content = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n" + //
"<beans\r\n" + //
" xmlns=\"http://www.springframework.org/schema/beans\"\r\n" + //
" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\r\n" + //
" xmlns:util=\"http://www.springframework.org/schema/util\"\r\n" + //
" xsi:schemaLocation=\"\r\n" + //
" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd\r\n"
+ //
" http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd\">\r\n"
+ //
"\r\n" + //
"</beans>";
String expected = content;
assertFormat(content, expected, settings);
// None
settings = createSettings();
XSISchemaLocationSplit.setSplit(XSISchemaLocationSplit.none, settings.getFormattingSettings());
assertFormat(content, expected, settings);
}
@Test
public void xsiSchemaLocationSplitOnElement() throws BadLocationException {
SharedSettings settings = createSettings();
XSISchemaLocationSplit.setSplit(XSISchemaLocationSplit.onElement, settings.getFormattingSettings());
String content = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n" + //
"<beans\r\n" + //
" xmlns=\"http://www.springframework.org/schema/beans\"\r\n" + //
" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\r\n" + //
" xmlns:util=\"http://www.springframework.org/schema/util\"\r\n" + //
" xsi:schemaLocation=\"\r\n" + //
" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd\r\n"
+ //
" http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd\">\r\n"
+ //
"\r\n" + //
"</beans>";
String expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n" + //
"<beans\r\n" + //
" xmlns=\"http://www.springframework.org/schema/beans\"\r\n" + //
" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\r\n" + //
" xmlns:util=\"http://www.springframework.org/schema/util\"\r\n" + //
" xsi:schemaLocation=\"http://www.springframework.org/schema/beans\r\n" + //
" http://www.springframework.org/schema/beans/spring-beans.xsd\r\n" + //
" http://www.springframework.org/schema/util\r\n" + //
" http://www.springframework.org/schema/util/spring-util.xsd\">\r\n" + //
"\r\n" + //
"</beans>";
assertFormat(content, expected, settings);
}
@Test
public void xsiSchemaLocationSplitOnPair() throws BadLocationException {
SharedSettings settings = createSettings();
XSISchemaLocationSplit.setSplit(XSISchemaLocationSplit.onPair, settings.getFormattingSettings());
String content = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n" + //
"<beans\r\n" + //
" xmlns=\"http://www.springframework.org/schema/beans\"\r\n" + //
" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\r\n" + //
" xmlns:util=\"http://www.springframework.org/schema/util\"\r\n" + //
" xsi:schemaLocation=\"\r\n" + //
" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd\r\n"
+ //
" http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd\">\r\n"
+ //
"\r\n" + //
"</beans>";
String expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n" + //
"<beans\r\n" + //
" xmlns=\"http://www.springframework.org/schema/beans\"\r\n" + //
" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\r\n" + //
" xmlns:util=\"http://www.springframework.org/schema/util\"\r\n" + //
" xsi:schemaLocation=\"http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd\r\n"
+ //
" http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd\">\r\n"
+ //
"\r\n" + //
"</beans>";
assertFormat(content, expected, settings);
}
@Test
public void xsiSchemaLocationEmpty() throws BadLocationException {
SharedSettings settings = createSettings();
XSISchemaLocationSplit.setSplit(XSISchemaLocationSplit.onElement, settings.getFormattingSettings());
String content = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n" + //
"<beans\r\n" + //
" xmlns=\"http://www.springframework.org/schema/beans\"\r\n" + //
" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\r\n" + //
" xmlns:util=\"http://www.springframework.org/schema/util\"\r\n" + //
" xsi:schemaLocation=" + //
"</beans>";
assertFormat(content, content, settings);
content = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n" + //
"<beans\r\n" + //
" xmlns=\"http://www.springframework.org/schema/beans\"\r\n" + //
" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\r\n" + //
" xmlns:util=\"http://www.springframework.org/schema/util\"\r\n" + //
" xsi:schemaLocation=\"" + //
"</beans>";
assertFormat(content, content, settings);
content = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n" + //
"<beans\r\n" + //
" xmlns=\"http://www.springframework.org/schema/beans\"\r\n" + //
" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\r\n" + //
" xmlns:util=\"http://www.springframework.org/schema/util\"\r\n" + //
" xsi:schemaLocation=\"\"" + //
"</beans>";
assertFormat(content, content, settings);
}
@Test
public void xsiSchemaLocationSplitOnElementWithTabs() throws BadLocationException {
SharedSettings settings = createSettings();
settings.getFormattingSettings().setTabSize(4);
settings.getFormattingSettings().setInsertSpaces(false);
XSISchemaLocationSplit.setSplit(XSISchemaLocationSplit.onElement, settings.getFormattingSettings());
String content = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n" + //
"<beans\r\n" + //
" xmlns=\"http://www.springframework.org/schema/beans\"\r\n" + //
" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\r\n" + //
" xmlns:util=\"http://www.springframework.org/schema/util\"\r\n" + //
" xsi:schemaLocation=\"\r\n" + //
" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd\r\n"
+ //
" http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd\">\r\n"
+ //
"\r\n" + //
"</beans>";
String expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n" + //
"<beans\r\n" + //
" xmlns=\"http://www.springframework.org/schema/beans\"\r\n" + //
" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\r\n" + //
" xmlns:util=\"http://www.springframework.org/schema/util\"\r\n" + //
" xsi:schemaLocation=\"http://www.springframework.org/schema/beans\r\n" + //
" http://www.springframework.org/schema/beans/spring-beans.xsd\r\n" + //
" http://www.springframework.org/schema/util\r\n" + //
" http://www.springframework.org/schema/util/spring-util.xsd\">\r\n" + //
"\r\n" + //
"</beans>";
assertFormat(content, expected, settings);
}
private static SharedSettings createSettings() {
SharedSettings settings = new SharedSettings();
settings.getFormattingSettings().setInsertSpaces(true);
settings.getFormattingSettings().setTabSize(2);
settings.getFormattingSettings().setSplitAttributes(SplitAttributes.splitNewLine);
settings.getFormattingSettings().setPreserveEmptyContent(true);
settings.getFormattingSettings().setLegacy(true);
return settings;
}
}