1d1969307SJohannes Altmanninger // RUN: %clang_cc1 -E %s > %t.src.cpp
2d1969307SJohannes Altmanninger // RUN: %clang_cc1 -E %s > %t.dst.cpp -DDEST
3d1969307SJohannes Altmanninger // RUN: clang-diff -dump-matches -s=10 %t.src.cpp %t.dst.cpp -- | FileCheck %s
4d1969307SJohannes Altmanninger //
5d1969307SJohannes Altmanninger // Test the behaviour of the matching according to the optimal tree edit
6d1969307SJohannes Altmanninger // distance, implemented with Zhang and Shasha's algorithm.
7d1969307SJohannes Altmanninger // Just for testing we use a tiny value of 10 for maxsize. Subtrees bigger than
8d1969307SJohannes Altmanninger // this size will not be processed by the optimal algorithm.
9d1969307SJohannes Altmanninger
10d1969307SJohannes Altmanninger #ifndef DEST
11d1969307SJohannes Altmanninger
f1()12d1969307SJohannes Altmanninger void f1() { {;} {{;}} }
13d1969307SJohannes Altmanninger
f2()14d1969307SJohannes Altmanninger void f2() { {;} {{;;;;;}} }
15d1969307SJohannes Altmanninger
f3()16d1969307SJohannes Altmanninger void f3() { {;} {{;;;;;;}} }
17d1969307SJohannes Altmanninger
18d1969307SJohannes Altmanninger #else
19d1969307SJohannes Altmanninger
f1()20d1969307SJohannes Altmanninger void f1() {
21d1969307SJohannes Altmanninger // Jaccard similarity = 3 / (5 + 4 - 3) = 3 / 6 >= 0.5
22d1969307SJohannes Altmanninger // The optimal matching algorithm should move the ; into the outer block
23d1969307SJohannes Altmanninger // CHECK: Match CompoundStmt(2) to CompoundStmt(2)
24d1969307SJohannes Altmanninger // CHECK-NOT: Match CompoundStmt(3)
25d1969307SJohannes Altmanninger // CHECK-NEXT: Match NullStmt(4) to NullStmt(3)
26d1969307SJohannes Altmanninger ; {{;}}
27d1969307SJohannes Altmanninger }
28d1969307SJohannes Altmanninger
f2()29d1969307SJohannes Altmanninger void f2() {
30d1969307SJohannes Altmanninger // Jaccard similarity = 7 / (10 + 10 - 7) >= 0.5
31d1969307SJohannes Altmanninger // As none of the subtrees is bigger than 10 nodes, the optimal algorithm
32d1969307SJohannes Altmanninger // will be run.
33d1969307SJohannes Altmanninger // CHECK: Match NullStmt(11) to NullStmt(9)
34d1969307SJohannes Altmanninger ;; {{;;;;;}}
35d1969307SJohannes Altmanninger }
36d1969307SJohannes Altmanninger
f3()37d1969307SJohannes Altmanninger void f3() {
38d1969307SJohannes Altmanninger // Jaccard similarity = 8 / (11 + 11 - 8) >= 0.5
39d1969307SJohannes Altmanninger // As the subtrees are bigger than 10 nodes, the optimal algorithm will not
40d1969307SJohannes Altmanninger // be run.
41d1969307SJohannes Altmanninger // CHECK: Delete NullStmt(22)
42d1969307SJohannes Altmanninger ;; {{;;;;;;}}
43d1969307SJohannes Altmanninger }
44*0dd86dc5SJohannes Altmanninger
45d1969307SJohannes Altmanninger #endif
46