Indenter bug corrections; indented files according to indenter
svn: r10371
This commit is contained in:
parent
707315b1b4
commit
08015efba8
|
@ -182,18 +182,20 @@
|
|||
(cond
|
||||
[(equal? opener #\{)
|
||||
(let* ([previous-open (get-sexp-start (sub1 open-at))]
|
||||
[brace? (and previous-open (equal? #\{ (get-character (sub1 previous-open))))]
|
||||
[base-line-start (and brace? (skip-whitespace (add1 previous-open) 'forward #f))])
|
||||
#;(printf "brace? ~a bls ~a~n" brace? base-line-start)
|
||||
[brace? (and previous-open
|
||||
(> (sub1 previous-open) 0)
|
||||
(equal? #\{ (get-character (sub1 previous-open))))]
|
||||
[base-line-text (and brace? (skip-whitespace (add1 previous-open) 'forward #f))]
|
||||
[base-line-start (and base-line-text (find-string eol 'backward base-line-text 0 #f))])
|
||||
#;(printf "brace? ~a blt ~a bls ~a~n" brace? base-line-text base-line-start)
|
||||
(cond
|
||||
[base-line-start (+ single-tab-stop
|
||||
(max 0 (sub1 (- base-line-start previous-open))))]
|
||||
(max 0 (sub1 (- base-line-text base-line-start))))]
|
||||
[brace? (+ single-tab-stop 0)]
|
||||
[else (+ single-tab-stop last-line-indent)]))]
|
||||
[(equal? opener #\()
|
||||
(+ (max 0
|
||||
(- open-at #;(find-string "(" 'forward last-line-start start-pos #f)
|
||||
last-line-start))
|
||||
(- open-at last-line-start))
|
||||
last-line-indent)]
|
||||
[(equal? opener #\[)
|
||||
(+ (max 0
|
||||
|
@ -240,6 +242,7 @@
|
|||
(cond
|
||||
[(not old-open) last-line-indent]
|
||||
[(and old-open (<= curr-open old-open)) last-line-indent]
|
||||
[(< (sub1 curr-open) 0) base-offset]
|
||||
[else
|
||||
(sensitive-indent last-line-indent last-line-start (get-character (sub1 curr-open)) curr-open)
|
||||
#;(+ single-tab-stop last-line-indent)]))]
|
||||
|
@ -251,6 +254,7 @@
|
|||
(cond
|
||||
[(not old-open) last-line-indent]
|
||||
[(and old-open (<= curr-open old-open)) last-line-indent]
|
||||
[(< (sub1 curr-open) 0) base-offset]
|
||||
[else
|
||||
(sensitive-indent last-line-indent last-line-start (get-character (sub1 curr-open)) curr-open)
|
||||
#;(+ single-tab-stop last-line-indent)]))]))])))])
|
||||
|
@ -311,15 +315,20 @@
|
|||
[end-para (position-paragraph (get-end-position))])
|
||||
(begin-edit-sequence)
|
||||
(let loop ([para start-para])
|
||||
#;(printf "in tabify outer loop ~a ~a~n" para end-para)
|
||||
(let* ([para-start (paragraph-start-position para)]
|
||||
[curr-white-space (skip-whitespace para-start 'forward #f)]
|
||||
[insertion (get-indentation (max 0 (sub1 para-start)))]
|
||||
[closer? #f]
|
||||
[delete? #f])
|
||||
(let loop ()
|
||||
#;(printf "in tabify inner loop ~a ~a, ~a ~n" para para-start curr-white-space)
|
||||
(let ([c (get-character para-start)]
|
||||
[class (classify-position para-start)])
|
||||
#;(printf "character is ~a, ~a~n" c class)
|
||||
(cond
|
||||
[(and (eq? 'white-space class)
|
||||
(not (= curr-white-space para-start))
|
||||
(not (char=? c #\015))
|
||||
(not (char=? c #\012)))
|
||||
(set! delete? #t)
|
||||
|
@ -332,8 +341,7 @@
|
|||
(insert (substring insertion 0 (max 0 (- (string-length insertion) single-tab-stop))) para-start para-start)]
|
||||
[(or delete? (not (eq? 'block-comment (classify-position para-start))))
|
||||
(insert insertion para-start para-start)]))
|
||||
(unless (= para end-para)
|
||||
(loop (+ para 1))))
|
||||
(unless (= para end-para) (loop (+ para 1))))
|
||||
(end-edit-sequence)))
|
||||
|
||||
(super-new)))
|
||||
|
|
|
@ -12,19 +12,19 @@ interface Automobile {
|
|||
}
|
||||
|
||||
class Car implements Automobile {
|
||||
|
||||
|
||||
String make;
|
||||
String model;
|
||||
int miles;
|
||||
double basePrice;
|
||||
|
||||
|
||||
Car(String make, String model, int miles, double basePrice) {
|
||||
this.make = make;
|
||||
this.model = model;
|
||||
this.miles = miles;
|
||||
this.basePrice = basePrice;
|
||||
}
|
||||
|
||||
|
||||
int milesTraveled() {
|
||||
return this.miles;
|
||||
}
|
||||
|
@ -35,10 +35,10 @@ class Car implements Automobile {
|
|||
Automobile travel(int miles) {
|
||||
return new Car(this.make, this.model, this.miles+miles, this.basePrice);
|
||||
}
|
||||
|
||||
|
||||
double price(int year) {
|
||||
if ((2006 - year) == 0) {
|
||||
return this.basePrice;
|
||||
return this.basePrice;
|
||||
} else {
|
||||
if ((2006 - year) > 0) {
|
||||
return this.basePrice - (this.basePrice / (2006 - year));
|
||||
|
@ -47,34 +47,34 @@ class Car implements Automobile {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
class CarExamples {
|
||||
|
||||
|
||||
CarExamples() { }
|
||||
|
||||
|
||||
Car myCar = new Car("Toyota","Tercel",100000, 16000.00);
|
||||
Car momCar = new Car("Honda","Excel",10000, 32000.00);
|
||||
|
||||
|
||||
boolean test1 = check this.myCar expect this.momCar;
|
||||
boolean test2 = check this.myCar.milesTraveled() expect 100000;
|
||||
|
||||
boolean testTravel() {
|
||||
return (check this.myCar.travel(10) expect new Car("Toyota","Tercel",100010, 16000.00)) ||
|
||||
(check this.momCar.travel(90000) expect this.myCar);
|
||||
(check this.momCar.travel(90000) expect this.myCar);
|
||||
}
|
||||
|
||||
|
||||
boolean testMakeModel() {
|
||||
return check this.myCar.makeAndModel() expect "ToyotaTercel";
|
||||
}
|
||||
|
||||
|
||||
boolean testPrice() {
|
||||
return (check this.myCar.price(2006) expect 16000.00 within .01) &&
|
||||
(check this.myCar.price(1991) expect 14933.33 within .01) &&
|
||||
(check this.myCar.price(2007) expect 32000.00 within .01);
|
||||
(check this.myCar.price(1991) expect 14933.33 within .01) &&
|
||||
(check this.myCar.price(2007) expect 32000.00 within .01);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
class Truck implements Automobile {
|
||||
|
@ -83,22 +83,22 @@ class Truck implements Automobile {
|
|||
int numDoors;
|
||||
boolean extendedBed;
|
||||
double basePrice;
|
||||
|
||||
|
||||
Truck( String make, int miles, int numDoors, boolean bed, double basePrice) {
|
||||
this.make = make;
|
||||
this.miles = miles;
|
||||
this.numDoors = numDoors;
|
||||
this.extendedBed = bed;
|
||||
this.basePrice = basePrice;
|
||||
this.make = make;
|
||||
this.miles = miles;
|
||||
this.numDoors = numDoors;
|
||||
this.extendedBed = bed;
|
||||
this.basePrice = basePrice;
|
||||
}
|
||||
|
||||
|
||||
int milesTraveled() { return this.miles; }
|
||||
String makeAndModel() {
|
||||
if (this.extendedBed) {
|
||||
return this.make.concat("Extended");
|
||||
return this.make.concat("Extended");
|
||||
} else {
|
||||
return this.make.concat(String.valueOf(this.numDoors));
|
||||
}
|
||||
return this.make.concat(String.valueOf(this.numDoors));
|
||||
}
|
||||
}
|
||||
Automobile travel(int miles) {
|
||||
return new Truck(this.make, this.miles + miles, this.numDoors, this.extendedBed, this.basePrice);
|
||||
|
@ -118,25 +118,25 @@ class Truck implements Automobile {
|
|||
class TruckExamples {
|
||||
Truck oneTruck = new Truck("Toyota",10000, 2,false,20000.00);
|
||||
Truck twoTruck = new Truck("Ford",100000,2,true,35000.00);
|
||||
|
||||
|
||||
boolean test1 = check this.oneTruck.milesTraveled() expect 10000;
|
||||
boolean test2 = check this.oneTruck expect this.twoTruck;
|
||||
|
||||
TruckExamples() { }
|
||||
|
||||
|
||||
boolean testPrice() {
|
||||
return (check this.oneTruck.price(2006) expect 20000.00 within .01) &&
|
||||
(check this.oneTruck.price(1996) expect 16000.00 within .01);
|
||||
}
|
||||
|
||||
|
||||
boolean testTravel() {
|
||||
return check this.oneTruck.travel(1000) expect new Truck("Toyota",11000,2,false,20000.00);
|
||||
}
|
||||
|
||||
|
||||
boolean testMakeAndModel() {
|
||||
return (check this.oneTruck.makeAndModel() expect "Toyota2") &&
|
||||
(check this.twoTruck.makeAndModel() expect "FordExtended");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -8,42 +8,42 @@ interface Automobile {
|
|||
}
|
||||
|
||||
abstract class Auto implements Automobile {
|
||||
int miles;
|
||||
int milesTraveled() { return miles; }
|
||||
|
||||
void travel(int miles) {
|
||||
int miles;
|
||||
int milesTraveled() { return miles; }
|
||||
|
||||
void travel(int miles) {
|
||||
this.miles = this.miles + miles;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class Car extends Auto {
|
||||
|
||||
|
||||
double basePrice;
|
||||
|
||||
|
||||
Car(int miles, double basePrice) {
|
||||
this.miles = miles;
|
||||
this.basePrice = basePrice;
|
||||
}
|
||||
|
||||
|
||||
double price(int year) {
|
||||
if ((2006 - year) == 0) {
|
||||
return this.basePrice;
|
||||
return this.basePrice;
|
||||
} else {
|
||||
if ((2006 - year) > 0) {
|
||||
return this.basePrice - (this.basePrice / (2006 - year));
|
||||
} else {
|
||||
return this.basePrice + (this.basePrice / (year - 2006));
|
||||
}
|
||||
}
|
||||
if ((2006 - year) > 0) {
|
||||
return this.basePrice - (this.basePrice / (2006 - year));
|
||||
} else {
|
||||
return this.basePrice + (this.basePrice / (year - 2006));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
class CarExamples {
|
||||
|
||||
|
||||
Car myCar = new Car(100000, 16000.00);
|
||||
Car momCar = new Car(10000, 32000.00);
|
||||
|
||||
|
||||
boolean test1 = check this.myCar expect this.momCar;
|
||||
boolean test2 = check this.myCar.milesTraveled() expect 100000;
|
||||
|
||||
|
@ -51,18 +51,18 @@ class CarExamples {
|
|||
myCar.travel(10);
|
||||
return (check this.myCar expect new Car(100010, 16000.00));
|
||||
}
|
||||
|
||||
|
||||
boolean testTravel2() {
|
||||
myCar.travel(10);
|
||||
return (check this.myCar expect new Car(100020, 16000.00));
|
||||
}
|
||||
|
||||
|
||||
boolean testPrice() {
|
||||
return (check this.myCar.price(2006) expect 16000.00 within .01) &&
|
||||
(check this.myCar.price(1991) expect 14933.33 within .01) &&
|
||||
(check this.myCar.price(2007) expect 32000.00 within .01);
|
||||
(check this.myCar.price(1991) expect 14933.33 within .01) &&
|
||||
(check this.myCar.price(2007) expect 32000.00 within .01);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
class Truck extends Auto {
|
||||
|
@ -70,21 +70,21 @@ class Truck extends Auto {
|
|||
int numDoors;
|
||||
boolean extendedBed;
|
||||
double basePrice;
|
||||
|
||||
|
||||
Truck( String make, int miles, int numDoors, boolean bed, double basePrice) {
|
||||
this.make = make;
|
||||
this.miles = miles;
|
||||
this.numDoors = numDoors;
|
||||
this.extendedBed = bed;
|
||||
this.basePrice = basePrice;
|
||||
this.make = make;
|
||||
this.miles = miles;
|
||||
this.numDoors = numDoors;
|
||||
this.extendedBed = bed;
|
||||
this.basePrice = basePrice;
|
||||
}
|
||||
|
||||
|
||||
String makeAndModel() {
|
||||
if (this.extendedBed) {
|
||||
return this.make.concat("Extended");
|
||||
return this.make.concat("Extended");
|
||||
} else {
|
||||
return this.make.concat(String.valueOf(this.numDoors));
|
||||
}
|
||||
return this.make.concat(String.valueOf(this.numDoors));
|
||||
}
|
||||
}
|
||||
double price( int year ) {
|
||||
// Uncomment to test runtime error behavior
|
||||
|
@ -101,25 +101,25 @@ class Truck extends Auto {
|
|||
class TruckExamples {
|
||||
Truck oneTruck = new Truck("Toyota",10000, 2,false,20000.00);
|
||||
Truck twoTruck = new Truck("Ford",100000,2,true,35000.00);
|
||||
|
||||
|
||||
boolean test1 = check this.oneTruck.milesTraveled() expect 10000;
|
||||
boolean test2 = check this.oneTruck expect this.twoTruck;
|
||||
|
||||
TruckExamples() { }
|
||||
|
||||
|
||||
boolean testPrice() {
|
||||
return (check this.oneTruck.price(2006) expect 20000.00 within .01) &&
|
||||
(check this.oneTruck.price(1996) expect 16000.00 within .01);
|
||||
}
|
||||
|
||||
|
||||
boolean testTravel() {
|
||||
oneTruck.travel(1000);
|
||||
return check this.oneTruck expect new Truck("Toyota",11000,2,false,20000.00);
|
||||
}
|
||||
|
||||
|
||||
boolean testMakeAndModel() {
|
||||
return (check this.oneTruck.makeAndModel() expect "Toyota2") &&
|
||||
(check this.twoTruck.makeAndModel() expect "FordExtended");
|
||||
}
|
||||
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user