1 /* 2 * The MIT License 3 * 4 * Copyright (c) <2010> <tap4j> 5 * 6 * Permission is hereby granted, free of charge, to any person obtaining a copy 7 * of this software and associated documentation files (the "Software"), to deal 8 * in the Software without restriction, including without limitation the rights 9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 * copies of the Software, and to permit persons to whom the Software is 11 * furnished to do so, subject to the following conditions: 12 * 13 * The above copyright notice and this permission notice shall be included in 14 * all copies or substantial portions of the Software. 15 * 16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 * THE SOFTWARE. 23 */ 24 package org.tap4j.parser; 25 26 import java.io.File; 27 import java.util.regex.Pattern; 28 29 import org.tap4j.model.TestSet; 30 31 /** 32 * TAP regex parser. 33 * 34 * @since 1.0 35 */ 36 public interface Parser { 37 38 /* -- Regular expressions -- */ 39 40 /** 41 * TAP Header Regex. 42 */ 43 String REGEX_HEADER = "\\s*TAP\\s*version\\s*(\\d+)\\s*(#\\s*(.*))?"; 44 45 /** 46 * TAP Plan Regex. 47 */ 48 String REGEX_PLAN = "\\s*(\\d+)(\\.{2})(\\d+)\\s*(skip\\s*([^#]+))?\\s*(#\\s*(.*))?"; 49 50 /** 51 * TAP Test Result Regex. 52 */ 53 String REGEX_TEST_RESULT = "\\s*(ok|not ok)\\s*(\\d+)\\s*([^#]*)?\\s*(#\\s*(SKIP|skip|TODO|todo)\\s*([^#]+))?\\s*(#\\s*(.*))?"; 54 55 /** 56 * TAP Bail Out! Regex. 57 */ 58 String REGEX_BAIL_OUT = "\\s*Bail out!\\s*([^#]+)?\\s*(#\\s*(.*))?"; 59 60 /** 61 * TAP Comment Regex. 62 */ 63 String REGEX_COMMENT = "\\s*#\\s*(.*)"; 64 65 /** 66 * TAP Footer Regex. 67 */ 68 String REGEX_FOOTER = "\\s*TAP\\s*([^#]*)?\\s*(#\\s*(.*))?"; 69 70 /* -- Patterns -- */ 71 72 /** 73 * TAP Header Regex Pattern. 74 */ 75 Pattern HEADER_PATTERN = Pattern.compile(REGEX_HEADER); 76 77 /** 78 * TAP Plan Regex Pattern. 79 */ 80 Pattern PLAN_PATTERN = Pattern.compile(REGEX_PLAN); 81 82 /** 83 * TAP Test Result Regex Pattern. 84 */ 85 Pattern TEST_RESULT_PATTERN = Pattern.compile(REGEX_TEST_RESULT); 86 87 /** 88 * TAP Bail Out! Regex Pattern. 89 */ 90 Pattern BAIL_OUT_PATTERN = Pattern.compile(REGEX_BAIL_OUT); 91 92 /** 93 * TAP Comment Regex Pattern. 94 */ 95 Pattern COMMENT_PATTERN = Pattern.compile(REGEX_COMMENT); 96 97 /** 98 * TAP Footer Regex Pattern. 99 */ 100 Pattern FOOTER_PATTERN = Pattern.compile(REGEX_FOOTER); 101 102 /** 103 * Parses a Test Result. 104 * 105 * @param tapLine TAP line 106 */ 107 void parseLine(String tapLine); 108 109 /** 110 * Parses a TAP Stream. 111 * 112 * @param tapStream TAP Stream 113 */ 114 TestSet parseTapStream(String tapStream); 115 116 /** 117 * Parses a TAP File. 118 * 119 * @param tapFile TAP File 120 */ 121 TestSet parseFile(File tapFile); 122 123 }