com.galenframework.parser.Expectations Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of galen-core Show documentation
Show all versions of galen-core Show documentation
A library for layout testing of websites
/*******************************************************************************
* Copyright 2017 Ivan Shubin http://galenframework.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
package com.galenframework.parser;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import com.galenframework.specs.Location;
import com.galenframework.specs.Side;
import com.galenframework.specs.colors.ColorRange;
import com.galenframework.specs.page.CorrectionsRect;
import com.galenframework.specs.Range;
import org.apache.commons.lang3.tuple.Pair;
public class Expectations {
public static List> expectThese(Expectation>...expectations) {
return Arrays.asList(expectations);
}
public static Expectation> sides() {
return new ExpectSides();
}
public static Expectation range() {
return new ExpectRange();
}
public static Expectation objectName() {
return new ExpectWord();
}
public static Expectation filePath() {
return new ExpectWord();
}
public static Expectationnumber() {
return new ExpectNumber();
}
public static Expectation word() {
return new ExpectWord();
}
public static Expectation commandLineArguments() {
return new ExpectCommandLineArguments();
}
public static boolean isDelimeter(char symbol) {
return symbol == ' ' || symbol == '\t';
}
public static boolean isWordDelimeter(char symbol) {
return symbol == ' ' || symbol == '\t' || symbol == ',';
}
public static boolean isNumeric(char symbol) {
return symbol == '-' || (symbol >= '0' && symbol <= '9');
}
public static Expectation> locations() {
return new ExpectLocations();
}
public static Expectation corrections() {
return new ExpectCorrection();
}
public static Expectation> colorRanges() {
return new ExpectColorRanges();
}
public static Expectation>> commaSeparatedRepeatedKeyValues() {
return new ExpectCommaSeparatedKeyValue();
}
public static List readAllWords(String arguments) {
List words = new LinkedList<>();
StringCharReader reader = new StringCharReader(arguments);
ExpectWord expectWord = new ExpectWord();
while(reader.hasMoreNormalSymbols()) {
String word = expectWord.read(reader);
if (!word.isEmpty()) {
words.add(word);
}
}
return words;
}
public static Expectation doubleQuotedText() {
return new Expectation() {
@Override
public String read(StringCharReader charReader) {
char firstNonWhiteSpaceSymbol = charReader.firstNonWhiteSpaceSymbol();
if (firstNonWhiteSpaceSymbol == '"') {
charReader.readSafeUntilSymbol('"');
return new ExpectString().read(charReader);
} else {
throw new SyntaxException("Expected \" symbol, got: " + firstNonWhiteSpaceSymbol);
}
}
};
}
public static ExpectationErrorRate errorRate() {
return new ExpectationErrorRate();
}
public static void expectNextWord(String expectedWord, StringCharReader reader) {
String word = word().read(reader);
if (!expectedWord.equals(word)) {
throw new SyntaxException("Expected: " + expectedWord + ", got: " + word);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy