@Test void testMappingWithCopybook() { String uri = "doc.cbl"; String copybook = "copybook.cpy"; Token enter = mock(Token.class); Token token0 = mock(Token.class); Token token1 = mock(Token.class); Token token2 = mock(Token.class); Token tokenEOF = mock(Token.class); Token exit = mock(Token.class); Range range = new Range(new Position(0, 0), new Position(0, 0)); Locality localityToShift = Locality.builder().uri(copybook).range(range).token("PROCESS").build(); Locality locality0 = Locality.builder().uri(copybook).range(range).token("token0").build(); Locality locality1 = Locality.builder().uri(copybook).range(range).token(".").build(); Locality localityNoMatch1 = Locality.builder().uri(copybook).range(range).token("nomatch1").build(); Locality localityNoMatch2 = Locality.builder().uri(copybook).range(range).token("nomatch2").build(); Locality locality2 = Locality.builder().uri(copybook).range(range).token("token1").build(); Locality localityEOF = Locality.builder().uri(copybook).range(range).token("<EOF>").build(); when(enter.getType()).thenReturn(COPYENTRY); when(enter.getText()).thenReturn(CPY_ENTER_TAG + CPY_URI_OPEN + copybook + CPY_URI_CLOSE); when(exit.getType()).thenReturn(COPYEXIT); when(token0.getType()).thenReturn(0); when(token0.getText()).thenReturn("token0"); when(token1.getType()).thenReturn(1); when(token1.getText()).thenReturn(". "); when(token2.getType()).thenReturn(2); when(token2.getText()).thenReturn("token1"); when(tokenEOF.getType()).thenReturn(3); when(tokenEOF.getText()).thenReturn("\r\n"); List<Token> tokens = List.of(enter, token0, token1, token2, tokenEOF, exit); List<Locality> localities = List.of(); List<Locality> cpyLocalities = List.of( localityToShift, locality0, locality1, localityNoMatch1, localityNoMatch2, locality2, localityEOF); Map<Integer, Integer> shifts = Map.of(0, 1); Map<String, DocumentMapping> mappings = Map.of( uri, new DocumentMapping(localities, shifts), copybook, new DocumentMapping(cpyLocalities, shifts)); Map<Token, Locality> expected = Map.of(token0, locality0, token1, locality1, token2, locality2, tokenEOF, localityEOF); Map<Token, Locality> actual = LocalityMappingUtils.createPositionMapping(tokens, mappings, uri); assertTrue(Maps.difference(expected, actual).areEqual()); }
public Map<Token, Locality> createPositionMapping( List<Token> tokens, Map<String, DocumentMapping> documentPositions, String documentUri) { Map<Token, Locality> result = new HashMap<>(); Deque<DocumentHierarchyLevel> documentHierarchyStack = new ArrayDeque<>(); enterDocument(documentUri, documentPositions, documentHierarchyStack); tokens.forEach(mapToken(documentPositions, result, documentHierarchyStack)); return result; }
LocalityMappingUtils { public Map<Token, Locality> createPositionMapping( List<Token> tokens, Map<String, DocumentMapping> documentPositions, String documentUri) { Map<Token, Locality> result = new HashMap<>(); Deque<DocumentHierarchyLevel> documentHierarchyStack = new ArrayDeque<>(); enterDocument(documentUri, documentPositions, documentHierarchyStack); tokens.forEach(mapToken(documentPositions, result, documentHierarchyStack)); return result; } }
LocalityMappingUtils { public Map<Token, Locality> createPositionMapping( List<Token> tokens, Map<String, DocumentMapping> documentPositions, String documentUri) { Map<Token, Locality> result = new HashMap<>(); Deque<DocumentHierarchyLevel> documentHierarchyStack = new ArrayDeque<>(); enterDocument(documentUri, documentPositions, documentHierarchyStack); tokens.forEach(mapToken(documentPositions, result, documentHierarchyStack)); return result; }  }
LocalityMappingUtils { public Map<Token, Locality> createPositionMapping( List<Token> tokens, Map<String, DocumentMapping> documentPositions, String documentUri) { Map<Token, Locality> result = new HashMap<>(); Deque<DocumentHierarchyLevel> documentHierarchyStack = new ArrayDeque<>(); enterDocument(documentUri, documentPositions, documentHierarchyStack); tokens.forEach(mapToken(documentPositions, result, documentHierarchyStack)); return result; }  Map<Token, Locality> createPositionMapping(
      List<Token> tokens, Map<String, DocumentMapping> documentPositions, String documentUri); }
LocalityMappingUtils { public Map<Token, Locality> createPositionMapping( List<Token> tokens, Map<String, DocumentMapping> documentPositions, String documentUri) { Map<Token, Locality> result = new HashMap<>(); Deque<DocumentHierarchyLevel> documentHierarchyStack = new ArrayDeque<>(); enterDocument(documentUri, documentPositions, documentHierarchyStack); tokens.forEach(mapToken(documentPositions, result, documentHierarchyStack)); return result; }  Map<Token, Locality> createPositionMapping(
      List<Token> tokens, Map<String, DocumentMapping> documentPositions, String documentUri);  }