Represents a test-file as described in the test_file_format RFC. @author David J. Pearce
| 26 | * |
| 27 | */ |
| 28 | public class TestFile implements Iterable<TestFile.Frame> { |
| 29 | private final HashMap<String,Object> config; |
| 30 | private final Frame[] frames; |
| 31 | |
| 32 | public TestFile(Map<String, Object> config, List<Frame> frames) { |
| 33 | this.config = new HashMap<>(config); |
| 34 | this.frames = frames.toArray(new Frame[frames.size()]); |
| 35 | } |
| 36 | |
| 37 | public <T> Optional<T> get(Class<T> kind, String option) { |
| 38 | Object o = config.get(option); |
| 39 | if(kind.isInstance(o)) { |
| 40 | return Optional.of((T) o); |
| 41 | } else { |
| 42 | return Optional.empty(); |
| 43 | } |
| 44 | } |
| 45 | |
| 46 | public Set<String> keys() { |
| 47 | return config.keySet(); |
| 48 | } |
| 49 | |
| 50 | public int size() { |
| 51 | return frames.length; |
| 52 | } |
| 53 | |
| 54 | @Override |
| 55 | public Iterator<Frame> iterator() { |
| 56 | return Arrays.stream(frames).iterator(); |
| 57 | } |
| 58 | |
| 59 | /** |
| 60 | * Represents a frame within a testfile. |
| 61 | * |
| 62 | * @author David J. Pearce |
| 63 | * |
| 64 | */ |
| 65 | public static class Frame { |
| 66 | public final Action[] actions; |
| 67 | public final Error[] markers; |
| 68 | |
| 69 | public Frame(List<Action> actions, List<Error> markers) { |
| 70 | this.actions = actions.toArray(new Action[actions.size()]); |
| 71 | this.markers = markers.toArray(new Error[markers.size()]); |
| 72 | } |
| 73 | |
| 74 | public void apply(Map<Trie,TextFile> state) { |
| 75 | for(Action a : actions) { |
| 76 | a.apply(state); |
| 77 | } |
| 78 | } |
| 79 | |
| 80 | @Override |
| 81 | public String toString() { |
| 82 | String r = ""; |
| 83 | for(Action a : actions) { |
| 84 | r += a.toString(); |
| 85 | } |
nothing calls this directly
no outgoing calls
no test coverage detected