Bläddra i källkod

PrintVisitor: test nested tags

Signed-off-by: Ranides Atterwim <ranides@gmail.com>
Mariusz Czarnowski 5 år sedan
förälder
incheckning
a459cae721

+ 8 - 3
assira/src/main/java/net/ranides/assira/reflection/walker/WalkerRules.java

@@ -72,10 +72,10 @@ public class WalkerRules {
             .hint("{PATH} {actual.shortname} = {value}")
         .prepare();
 
-    private final Map<Object, ResolveFormat> tags;
+    private final Map<Object, Object> tags;
     private final List<RuleEntry> rules;
 
-    private WalkerRules(Map<Object, ResolveFormat> tags, List<RuleEntry> rules) {
+    private WalkerRules(Map<Object, Object> tags, List<RuleEntry> rules) {
         this.tags = new HashMap<>(tags);
         this.rules = new ArrayList<>(rules);
     }
@@ -94,13 +94,18 @@ public class WalkerRules {
 
     public static class Builder {
 
-        private final Map<Object, ResolveFormat> tags = new HashMap<>();
+        private final Map<Object, Object> tags = new HashMap<>();
         private final List<RuleEntry> rules = new ArrayList<>();
 
         public WalkerRules prepare() {
             return new WalkerRules(tags, rules);
         }
 
+        public Builder tag(String name, Object value) {
+            this.tags.put(name, value);
+            return this;
+        }
+
         public Builder tag(String name, String value) {
             this.tags.put(name, ResolveFormat.compile(value));
             return this;

+ 5 - 6
assira/src/test/java/net/ranides/assira/reflection/walker/ObjectWalkerTest.java

@@ -4,6 +4,7 @@ import lombok.Builder;
 import lombok.Data;
 import lombok.Singular;
 import net.ranides.assira.junit.NewAssert;
+import net.ranides.assira.trace.TraceUtils;
 import org.jetbrains.annotations.Debug;
 import org.junit.Test;
 
@@ -245,15 +246,13 @@ public class ObjectWalkerTest {
                 .match(Point.class)
                 .text("<native>")
             .rules(WalkerRules.DEFAULT)
-            .tag("PATH", "{typeName,text,20} {namePath,text,-50}")
+            .tag("TEST", TraceUtils.getTestFrame().orElse(null))
+            .tag("HOME", "#{TEST.methodName}")
+            .tag("PATH", "{HOME}: {typeName,text,20} {namePath,text,-50}")
             .prepare()
             .visitor(writer);
 
-        List<Object> list = Arrays.asList(record1, foo1);
-
-        ObjectWalker.walk(list, "record", visitor);
-
-        System.out.println(writer.toString());
+        ObjectWalker.walk(Arrays.asList(record1, foo1), "record", visitor);
 
         NewAssert.assertLineEquals(TestFiles.WALK_MATCH_TEXT, writer.toString());
     }

+ 46 - 46
assira/src/test/resources/reflective/walker/matchText.txt

@@ -1,46 +1,46 @@
-             List<E> record                                             List<E>.size = 2
-                   E record/[0]                                         Record = <native>
-              byte[] record/[0]/binary                                  byte[] = '32 56 A0 F3 47 8A'
-            String[] record/[0]/lines                                   String[].size = 6
-              String record/[0]/lines/[0]                               String = 'one'
-              String record/[0]/lines/[1]                               String = 'two'
-              String record/[0]/lines/[2]                               String = 'three'
-              String record/[0]/lines/[3]                               String = 'four'
-              String record/[0]/lines/[4]                               String = 'five'
-              String record/[0]/lines/[5]                               String = 'six'
-              char[] record/[0]/sequence                                char[] = 'hello world'
-                 int record/[0]/uid                                     Integer = 556
-                   E record/[1]                                         Foo = <native>
-                 Bar record/[1]/bar                                     Bar = <native>
-              String record/[1]/bar/hex                                 String = '0xFAD'
-              String record/[1]/bar/uid                                 String = '456'
-                 Bar record/[1]/empty                                   Bar = <null>
-        List<String> record/[1]/names                                   List<String>.size = 3
-              String record/[1]/names/[0]                               String = 'John'
-              String record/[1]/names/[1]                               String = 'Jenny'
-              String record/[1]/names/[2]                               String = 'Adam'
-  Map<Integer,Point> record/[1]/points                                  Map<Integer,Point>.size = 6
-               Point record/[1]/points/[17]                             Point = <native>
-                 int record/[1]/points/[17]/x                           Integer = 21
-                 int record/[1]/points/[17]/y                           Integer = 6
-                 int record/[1]/points/[17]/z                           Integer = 4
-               Point record/[1]/points/[18]                             Point = <native>
-                 int record/[1]/points/[18]/x                           Integer = 21
-                 int record/[1]/points/[18]/y                           Integer = 6
-                 int record/[1]/points/[18]/z                           Integer = 4
-               Point record/[1]/points/[21]                             Point = <native>
-                 int record/[1]/points/[21]/x                           Integer = 9
-                 int record/[1]/points/[21]/y                           Integer = 7
-                 int record/[1]/points/[21]/z                           Integer = 5
-               Point record/[1]/points/[3]                              Point = <native>
-                 int record/[1]/points/[3]/x                            Integer = 9
-                 int record/[1]/points/[3]/y                            Integer = 19
-                 int record/[1]/points/[3]/z                            Integer = 11
-               Point record/[1]/points/[8]                              Point = <native>
-                 int record/[1]/points/[8]/x                            Integer = 9
-                 int record/[1]/points/[8]/y                            Integer = 32
-                 int record/[1]/points/[8]/z                            Integer = 2
-               Point record/[1]/points/[88]                             Point = <native>
-                 int record/[1]/points/[88]/x                           Integer = 21
-                 int record/[1]/points/[88]/y                           Integer = 6
-                 int record/[1]/points/[88]/z                           Integer = 4
+#matchText:              List<E> record                                             List<E>.size = 2
+#matchText:                    E record/[0]                                         Record = <native>
+#matchText:               byte[] record/[0]/binary                                  byte[] = '32 56 A0 F3 47 8A'
+#matchText:             String[] record/[0]/lines                                   String[].size = 6
+#matchText:               String record/[0]/lines/[0]                               String = 'one'
+#matchText:               String record/[0]/lines/[1]                               String = 'two'
+#matchText:               String record/[0]/lines/[2]                               String = 'three'
+#matchText:               String record/[0]/lines/[3]                               String = 'four'
+#matchText:               String record/[0]/lines/[4]                               String = 'five'
+#matchText:               String record/[0]/lines/[5]                               String = 'six'
+#matchText:               char[] record/[0]/sequence                                char[] = 'hello world'
+#matchText:                  int record/[0]/uid                                     Integer = 556
+#matchText:                    E record/[1]                                         Foo = <native>
+#matchText:                  Bar record/[1]/bar                                     Bar = <native>
+#matchText:               String record/[1]/bar/hex                                 String = '0xFAD'
+#matchText:               String record/[1]/bar/uid                                 String = '456'
+#matchText:                  Bar record/[1]/empty                                   Bar = <null>
+#matchText:         List<String> record/[1]/names                                   List<String>.size = 3
+#matchText:               String record/[1]/names/[0]                               String = 'John'
+#matchText:               String record/[1]/names/[1]                               String = 'Jenny'
+#matchText:               String record/[1]/names/[2]                               String = 'Adam'
+#matchText:   Map<Integer,Point> record/[1]/points                                  Map<Integer,Point>.size = 6
+#matchText:                Point record/[1]/points/[17]                             Point = <native>
+#matchText:                  int record/[1]/points/[17]/x                           Integer = 21
+#matchText:                  int record/[1]/points/[17]/y                           Integer = 6
+#matchText:                  int record/[1]/points/[17]/z                           Integer = 4
+#matchText:                Point record/[1]/points/[18]                             Point = <native>
+#matchText:                  int record/[1]/points/[18]/x                           Integer = 21
+#matchText:                  int record/[1]/points/[18]/y                           Integer = 6
+#matchText:                  int record/[1]/points/[18]/z                           Integer = 4
+#matchText:                Point record/[1]/points/[21]                             Point = <native>
+#matchText:                  int record/[1]/points/[21]/x                           Integer = 9
+#matchText:                  int record/[1]/points/[21]/y                           Integer = 7
+#matchText:                  int record/[1]/points/[21]/z                           Integer = 5
+#matchText:                Point record/[1]/points/[3]                              Point = <native>
+#matchText:                  int record/[1]/points/[3]/x                            Integer = 9
+#matchText:                  int record/[1]/points/[3]/y                            Integer = 19
+#matchText:                  int record/[1]/points/[3]/z                            Integer = 11
+#matchText:                Point record/[1]/points/[8]                              Point = <native>
+#matchText:                  int record/[1]/points/[8]/x                            Integer = 9
+#matchText:                  int record/[1]/points/[8]/y                            Integer = 32
+#matchText:                  int record/[1]/points/[8]/z                            Integer = 2
+#matchText:                Point record/[1]/points/[88]                             Point = <native>
+#matchText:                  int record/[1]/points/[88]/x                           Integer = 21
+#matchText:                  int record/[1]/points/[88]/y                           Integer = 6
+#matchText:                  int record/[1]/points/[88]/z                           Integer = 4