Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 217821 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/wst/css/ui/tests/viewer/TestCSSContentAssist.java (-2 / +64 lines)
Lines 10-16 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.wst.css.ui.tests.viewer;
11
package org.eclipse.wst.css.ui.tests.viewer;
12
12
13
import java.io.ByteArrayOutputStream;
14
import java.io.FileNotFoundException;
13
import java.io.IOException;
15
import java.io.IOException;
16
import java.io.InputStream;
14
17
15
import junit.framework.Assert;
18
import junit.framework.Assert;
16
import junit.framework.TestCase;
19
import junit.framework.TestCase;
Lines 41-46 Link Here
41
44
42
public class TestCSSContentAssist extends TestCase {
45
public class TestCSSContentAssist extends TestCase {
43
46
47
	private static final String UTF_8 = "UTF-8";
44
	protected String projectName = null;
48
	protected String projectName = null;
45
	protected String fileName = null;
49
	protected String fileName = null;
46
	protected String resourcesFolder = null;
50
	protected String resourcesFolder = null;
Lines 55-62 Link Here
55
	protected void setUp() throws Exception {
59
	protected void setUp() throws Exception {
56
60
57
		super.setUp();
61
		super.setUp();
58
		projectName = "CSSContentAssistForMedia";
62
		projectName = "CSSContentAssist";
59
		fileName = "mediaexample.css";
63
64
		if (fileName == null) {
65
			fileName = "mediaexample.css";
66
		}
60
		resourcesFolder = "/testresources";
67
		resourcesFolder = "/testresources";
61
68
62
		String filePath = setupProject();
69
		String filePath = setupProject();
Lines 127-132 Link Here
127
		super.tearDown();
134
		super.tearDown();
128
	}
135
	}
129
136
137
	/**
138
	 * must release model (from edit) after
139
	 * 
140
	 * @param filename
141
	 *            relative to this class (TestFormatProcessorCSS)
142
	 */
143
	private IStructuredModel getModelForEdit(final String file)	throws IOException {
144
145
		IStructuredModel model = null;
146
		IModelManager modelManager = StructuredModelManager.getModelManager();
147
		InputStream inStream = getClass().getResourceAsStream(file);
148
		if (inStream == null)
149
			throw new FileNotFoundException("Can't file resource stream " + file);
150
		final String baseFile = getClass().getResource(file).toString();
151
		model = modelManager.getModelForEdit(baseFile, inStream, null);
152
		return model;
153
	}
154
130
	public void testContentAssistInsideMedia() throws Exception {
155
	public void testContentAssistInsideMedia() throws Exception {
131
156
132
		try {
157
		try {
Lines 139-142 Link Here
139
			model.releaseFromEdit();
164
			model.releaseFromEdit();
140
		}
165
		}
141
	}
166
	}
167
168
	public void testContentAssistCompletion() throws Exception {
169
		IStructuredModel afterModel = null;
170
		try {
171
			fileName = "contentAssistCompletion.css";
172
			setUp();
173
174
			CSSContentAssistProcessor processor = new CSSContentAssistProcessor();
175
			ICompletionProposal[] proposals = processor
176
					.computeCompletionProposals(sourceViewer, 11);
177
			assertTrue("No proposals at offset.", proposals.length > 2);
178
			ICompletionProposal proposal = proposals[1];
179
			assertEquals("Wrong proposal returned for H2.", "h2", proposal.getDisplayString());
180
			proposal.apply(document);
181
182
			String resultfile = "results/contentAssistCompletion-result.css";
183
			afterModel = getModelForEdit(resultfile);
184
			assertNotNull("could not retrieve structured model for : "+ resultfile, afterModel);
185
186
			ByteArrayOutputStream updatedBytes = new ByteArrayOutputStream();
187
			model.save(updatedBytes);
188
189
			ByteArrayOutputStream afterBytes = new ByteArrayOutputStream();
190
			afterModel.save(afterBytes);
191
192
			String updatedContents = new String(updatedBytes.toByteArray(),UTF_8);
193
			String expectedContents = new String(afterBytes.toByteArray(), UTF_8);
194
			assertTrue("Edited document differs from the expected", updatedContents.equalsIgnoreCase(expectedContents));
195
196
		} finally {
197
			if (model != null)
198
				model.releaseFromEdit();
199
			if (afterModel != null)
200
				afterModel.releaseFromEdit();
201
		}
202
	}
203
142
}
204
}
(-)testresources/contentAssistCompletion.css (+9 lines)
Added Link Here
1
H1 {
2
	
3
}
4
5
H
6
7
H3 {
8
	
9
}
(-)src/org/eclipse/wst/css/ui/tests/viewer/results/contentAssistCompletion-result.css (+11 lines)
Added Link Here
1
H1 {
2
	
3
}
4
5
h2 {
6
	
7
}
8
9
H3 {
10
	
11
}

Return to bug 217821