source: trunk/tester/scripts/stringdiffs.tcl @ 2241

Last change on this file since 2241 was 2139, checked in by mmc, 14 years ago

Finished everything for a 1.0 version of the tester tool. The tester
successfully reports errors for the tool in the "example" directory.
It catches differences in input values and output results. It can look
for tests that are expected to fail and detect mismatches in their
standard output. Still needs a "build" mode to create/modify tests,
but this much handles the regression testing part pretty well.

File size: 8.5 KB
Line 
1# ----------------------------------------------------------------------
2#  COMPONENT: stringdiffs - show diff info between two strings
3#
4#  This component is used when examining the details of a particular
5#  diff.  It shows two strings with either inline or side-by-side
6#  diffs.
7# ======================================================================
8#  AUTHOR:  Michael McLennan, Purdue University
9#  Copyright (c) 2010-2011  Purdue Research Foundation
10#
11#  See the file "license.terms" for information on usage and
12#  redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
13# ======================================================================
14package require Itk
15package require RapptureGUI
16
17namespace eval Rappture::Tester { # forward declaration }
18
19option add *StringDiffs.titleFont {Arial -12 bold} widgetDefault
20option add *StringDiffs.bodyFont {Courier -12} widgetDefault
21option add *StringDiffs.bodyBackground white widgetDefault
22
23itcl::class Rappture::Tester::StringDiffs {
24    inherit itk::Widget
25
26    itk_option define -title title Title ""
27    itk_option define -title1 title1 Title1 ""
28    itk_option define -title2 title2 Title2 ""
29
30    constructor {args} { # defined later }
31    method show {v1 v2}
32
33    protected method _yview {args}
34}
35
36# ----------------------------------------------------------------------
37# CONSTRUCTOR
38# ----------------------------------------------------------------------
39itcl::body Rappture::Tester::StringDiffs::constructor {args} {
40    # viewer for inline diffs
41    itk_component add inline {
42        frame $itk_interior.inline
43    }
44
45    itk_component add title {
46        label $itk_component(inline).title -justify left -anchor w
47    } {
48        usual
49        rename -font -titlefont titleFont Font
50    }
51    pack $itk_component(title) -side top -fill x
52
53    itk_component add scrl {
54        Rappture::Scroller $itk_component(inline).scrl \
55            -xscrollmode auto -yscrollmode auto
56    }
57    pack $itk_component(scrl) -expand yes -fill both
58
59    itk_component add body {
60        Rappture::Diffview $itk_component(scrl).diffs \
61            -highlightthickness 0 \
62            -diff 1->2 -layout inline
63    } {
64        keep -foreground -cursor
65        keep -addedbackground -addedforeground
66        keep -deletedbackground -deletedforeground -overstrike
67        keep -changedbackground -changedforeground
68        rename -background -bodybackground bodyBackground Background
69        rename -font -bodyfont bodyFont Font
70    }
71    $itk_component(scrl) contents $itk_component(body)
72
73    # viewer for side-by-side diffs
74    itk_component add sidebyside {
75        frame $itk_interior.sbys
76    }
77
78    itk_component add title1 {
79        label $itk_component(sidebyside).title1 -justify left -anchor w
80    } {
81        usual
82        rename -font -titlefont titleFont Font
83    }
84    itk_component add body1 {
85        Rappture::Diffview $itk_component(sidebyside).s1 \
86            -highlightthickness 0 \
87            -diff 2->1 -layout sidebyside
88    } {
89        keep -background -foreground -cursor
90        keep -addedbackground -addedforeground
91        keep -deletedbackground -deletedforeground -overstrike
92        keep -changedbackground -changedforeground
93        rename -background -bodybackground bodyBackground Background
94        rename -font -bodyfont bodyFont Font
95    }
96    itk_component add xsbar1 {
97        scrollbar $itk_component(sidebyside).xsbar1 -orient horizontal \
98            -command [list $itk_component(body1) xview]
99    }
100
101    itk_component add title2 {
102        label $itk_component(sidebyside).title2 -justify left -anchor w
103    } {
104        usual
105        rename -font -titlefont titleFont Font
106    }
107    itk_component add body2 {
108        Rappture::Diffview $itk_component(sidebyside).s2 \
109            -highlightthickness 0 \
110            -diff 1->2 -layout sidebyside
111    } {
112        keep -background -foreground -cursor
113        keep -addedbackground -addedforeground
114        keep -deletedbackground -deletedforeground -overstrike
115        keep -changedbackground -changedforeground
116        rename -background -bodybackground bodyBackground Background
117        rename -font -bodyfont bodyFont Font
118    }
119    itk_component add xsbar2 {
120        scrollbar $itk_component(sidebyside).xsbar2 -orient horizontal \
121            -command [list $itk_component(body2) xview]
122    }
123
124    itk_component add ysbar {
125        scrollbar $itk_component(sidebyside).ysbar -orient vertical \
126            -command [itcl::code $this _yview]
127    }
128    $itk_component(body1) configure \
129        -xscrollcommand [list $itk_component(xsbar1) set] \
130        -yscrollcommand [list $itk_component(ysbar) set]
131    $itk_component(body2) configure \
132        -xscrollcommand [list $itk_component(xsbar2) set]
133
134    grid $itk_component(title1) -row 0 -column 0 -sticky nsew
135    grid $itk_component(body1) -row 1 -column 0 -sticky nsew
136    grid $itk_component(xsbar1) -row 2 -column 0 -sticky ew
137    grid $itk_component(ysbar) -row 1 -column 1 -sticky ns
138    grid $itk_component(title2) -row 0 -column 2 -sticky nsew
139    grid $itk_component(body2) -row 1 -column 2 -sticky nsew
140    grid $itk_component(xsbar2) -row 2 -column 2 -sticky ew
141    grid columnconfigure $itk_component(sidebyside) 0 -weight 1
142    grid columnconfigure $itk_component(sidebyside) 2 -weight 1
143    grid rowconfigure $itk_component(sidebyside) 1 -weight 1
144
145    eval itk_initialize $args
146}
147
148itk::usual StringDiffs {
149    keep -background -foreground -cursor
150    keep -titlefont -bodyfont
151}
152
153# ----------------------------------------------------------------------
154# USAGE: show <v1> <v2>
155#
156# Loads two values into the viewer and shows their differences.
157# If the strings are short, the diffs are shown inline.  Otherwise,
158# they are show with side-by-side viewers.
159# ----------------------------------------------------------------------
160itcl::body Rappture::Tester::StringDiffs::show {v1 v2} {
161    #
162    # HACK ALERT!  The Diffview widget doesn't handle tabs at all.
163    #   We'll convert all tabs to a few spaces until we get a chance
164    #   to fix it properly.
165    #
166    set v1 [string map [list \t "   "] $v1]
167    set v2 [string map [list \t "   "] $v2]
168
169    #
170    # Figure out whether to show inline diffs or side-by-side.
171    # If the strings are short, it looks better inline.  Otherwise,
172    # use side-by-side.
173    #
174    foreach w [pack slaves $itk_interior] {
175        pack forget $w
176    }
177    if {[llength [split $v1 \n]] > 10 || [llength [split $v2 \n]] > 10} {
178        set which "sidebyside"
179    } else {
180        set which "inline"
181    }
182    pack $itk_component($which) -expand yes -fill both
183
184    switch -- $which {
185        inline {
186            $itk_component(body) text 1 $v1
187            $itk_component(body) text 2 $v2
188            $itk_component(body1) text 1 ""
189            $itk_component(body1) text 2 ""
190            $itk_component(body2) text 1 ""
191            $itk_component(body2) text 2 ""
192        }
193        sidebyside {
194            $itk_component(body1) text 1 $v1
195            $itk_component(body1) text 2 $v2
196            $itk_component(body2) text 1 $v1
197            $itk_component(body2) text 2 $v2
198            $itk_component(body) text 1 ""
199            $itk_component(body) text 2 ""
200        }
201    }
202}
203
204# ----------------------------------------------------------------------
205# USAGE: _yview <arg> <arg>...
206#
207# Loads two values into the viewer and shows their differences.
208# If the strings are short, the diffs are shown inline.  Otherwise,
209# they are show with side-by-side viewers.
210# ----------------------------------------------------------------------
211itcl::body Rappture::Tester::StringDiffs::_yview {args} {
212    eval $itk_component(body1) yview $args
213    eval $itk_component(body2) yview $args
214}
215
216# ----------------------------------------------------------------------
217# CONFIGURATION OPTIONS: -title -title1 -title2
218# ----------------------------------------------------------------------
219itcl::configbody Rappture::Tester::StringDiffs::title {
220    # if there is no -title for inline diffs, use -title1
221    if {$itk_option(-title) eq ""} {
222        $itk_component(title) configure -text $itk_option(-title1)
223    } else {
224        $itk_component(title) configure -text $itk_option(-title)
225    }
226}
227
228itcl::configbody Rappture::Tester::StringDiffs::title1 {
229    # if there is no -title for inline diffs, use -title1
230    if {$itk_option(-title) eq ""} {
231        $itk_component(title) configure -text $itk_option(-title1)
232    }
233    $itk_component(title1) configure -text $itk_option(-title1)
234}
235
236itcl::configbody Rappture::Tester::StringDiffs::title2 {
237    $itk_component(title2) configure -text $itk_option(-title2)
238}
Note: See TracBrowser for help on using the repository browser.