Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: f460fbcf3e88cc6958b588f02f0ecdd7f2fef16a (plain) (blame)
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
/*******************************************************************************
 * Copyright (c) 2007, 2013 David Green and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     David Green - initial API and implementation
 *******************************************************************************/
package org.eclipse.mylyn.wikitext.textile.internal.validation;

import java.util.List;

import org.eclipse.mylyn.wikitext.textile.internal.validation.BlockWhitespaceRule;
import org.eclipse.mylyn.wikitext.validation.MarkupValidator;
import org.eclipse.mylyn.wikitext.validation.ValidationProblem;

import junit.framework.TestCase;

/**
 * @author David Green
 */
public class BlockWhitespaceRuleTest extends TestCase {

	private BlockWhitespaceRule rule;

	private MarkupValidator validator;

	@Override
	public void setUp() {
		rule = new BlockWhitespaceRule();

		validator = new MarkupValidator();
		validator.getRules().add(rule);
	}

	public void testNoMatch() {
		final String markup = "bc. \nfoo";
		ValidationProblem problem = rule.findProblem(markup, 0, markup.length());
		
		assertNull(problem);
	}

	public void testNoMatch2() {
		final String markup = "\nabc.\nfoo";
		ValidationProblem problem = rule.findProblem(markup, 0, markup.length());
		
		assertNull(problem);
	}

	public void testMatch() {
		final String markup = "bc.\nfoo";
		ValidationProblem problem = rule.findProblem(markup, 0, markup.length());
		
		assertNotNull(problem);
		assertEquals(0, problem.getOffset());
	}

	public void testMatch2() {
		final String markup = "\nbc.\nfoo";
		ValidationProblem problem = rule.findProblem(markup, 0, markup.length());
		
		assertNotNull(problem);
		assertEquals(1, problem.getOffset());
	}

	public void testMatch3() {
		final String markup = "\n\n\nbc..\nfoo";
		ValidationProblem problem = rule.findProblem(markup, 0, markup.length());
		
		assertNotNull(problem);
		assertEquals(3, problem.getOffset());
	}

	public void testValidator() {
		String markup = "h1. Foo\n\nbc. bar\n\npre.\nsdf\n\nbc.\n\n";
		List<ValidationProblem> result = validator.validate(markup);
		assertEquals(2, result.size());
		
		assertEquals(18, result.get(0).getOffset());
		assertEquals(4, result.get(0).getLength());
		assertEquals(28, result.get(1).getOffset());
		assertEquals(3, result.get(1).getLength());
	}
}

Back to the top