PageRenderTime 146ms CodeModel.GetById 125ms app.highlight 16ms RepoModel.GetById 1ms app.codeStats 0ms

/tst/org/diffkit/diff/sns/tst/TestFormatter.groovy

http://diffkit.googlecode.com/
Groovy | 74 lines | 44 code | 12 blank | 18 comment | 2 complexity | fc68500230dd0eac8c35387aaf64540e MD5 | raw file
 1/**
 2 * Copyright 2010-2011 Joseph Panico
 3 *
 4 * Licensed under the Apache License, Version 2.0 (the "License");
 5 * you may not use this file except in compliance with the License.
 6 * You may obtain a copy of the License at
 7 *
 8 *   http://www.apache.org/licenses/LICENSE-2.0
 9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package org.diffkit.diff.sns.tst
17
18import org.diffkit.diff.engine.DKColumnComparison 
19import org.diffkit.diff.engine.DKColumnDiffRow 
20import org.diffkit.diff.engine.DKColumnModel 
21import org.diffkit.diff.engine.DKContext 
22import org.diffkit.diff.engine.DKRowDiff 
23import org.diffkit.diff.engine.DKSide;
24import org.diffkit.diff.engine.DKStandardTableComparison 
25import org.diffkit.diff.engine.DKTableModel;
26import org.diffkit.diff.engine.DKDiff;
27import org.diffkit.diff.sns.DKDefaultFormatter;
28import org.diffkit.diff.diffor.DKEqualsDiffor
29
30import groovy.util.GroovyTestCase;
31
32
33/**
34 * @author jpanico
35 */
36public class TestFormatter  extends GroovyTestCase {
37	
38	
39	public void testDefaultFormatter(){
40		Object[] row = ['1111', '1111', 1]
41		def plan = this.createSimplePlan()
42		def keyValues = plan.getRowKeyValues( row, DKSide.LEFT_INDEX)
43		def displayValues = plan.getRowDisplayValues( row, DKSide.LEFT_INDEX )
44		DKRowDiff rowDiff = [1, row, DKSide.LEFT, plan]
45		def context = new DKContext()
46		String formatted = DKDefaultFormatter.instance.formatRowDiff(rowDiff, context)
47		
48		assert formatted == '!{column2=1111, column3=1}\n>'
49		
50		DKColumnDiffRow diffRow = [1, row, row, plan]
51		def columnDiff = diffRow.createDiff(1, '1111', 'xxxx')
52		formatted = DKDefaultFormatter.instance.formatColumnDiff(columnDiff, context)
53		println "formatted->$formatted"
54		assert formatted == '@{column2=1111, column3=1}\ncolumn2\n<1111\n>xxxx'
55		
56	}
57	
58	private DKStandardTableComparison createSimplePlan() {
59		DKTableModel tableModel = this.createSimpleTableModel();
60		DKColumnComparison[] map = DKColumnComparison.createColumnPlans( tableModel,tableModel, (int[]) [1], DKEqualsDiffor.instance)
61		DKStandardTableComparison plan = new DKStandardTableComparison(tableModel, tableModel, DKDiff.Kind.BOTH, map, (int[])[0], (int[][])[[1,2],[1,2]], (long)100)
62		return plan
63	}
64	
65	private DKTableModel createSimpleTableModel(){
66		DKColumnModel column1 = [0, 'column1', DKColumnModel.Type.STRING]
67		DKColumnModel column2 = [1, 'column2', DKColumnModel.Type.STRING]
68		DKColumnModel column3 = [2, 'column3', DKColumnModel.Type.INTEGER]
69		DKColumnModel[] columns = [column1, column2, column3]
70		int[] key = [0,2]
71		
72		return new DKTableModel("simple_table_model",columns, key) 
73	}
74}