Skip to content

Commit

Permalink
fix rebase conflicts and bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
dxu committed May 7, 2016
1 parent 1927257 commit 4dbb917
Show file tree
Hide file tree
Showing 6 changed files with 290 additions and 351 deletions.
88 changes: 44 additions & 44 deletions formatTest/unit_tests/expected_output/basicStructures.re
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2015-present, Facebook, Inc. All rights reserved.
/* Copyright (c) 2015-present, Facebook, Inc. All rights reserved. */
let run () => TestUtils.printSection "Basic Structures";

while something {
Expand Down Expand Up @@ -36,7 +36,7 @@ let x = !(!foo).bar;

let x = !(!foo)#bar;

// Prefix operator
/* Prefix operator */
let x = !!foo.bar;

let x = !!foo#bar;
Expand Down Expand Up @@ -64,9 +64,9 @@ let x = !!foo.bar;

let x = !!foo#bar;

// Comments
//Below is an empty comment
//
/* Comments */
/*Below is an empty comment*/
/**/
/** IF
*============================================================================
*/
Expand Down Expand Up @@ -109,7 +109,7 @@ let loop appTime frameTime => {
process appTime frameTime
};

// These parens should be kept around the entire last if/then/else
/* These parens should be kept around the entire last if/then/else */
if something {
if somethingElse {
()
Expand All @@ -118,7 +118,7 @@ if something {
}
};

// These parens should be kept around just the last if/then
/* These parens should be kept around just the last if/then*/
if something {
if somethingElse {
()
Expand All @@ -137,7 +137,7 @@ if true {
}
};

// Should print two
/* Should print two */
if true {
if false {
print_string "one"
Expand All @@ -146,7 +146,7 @@ if true {
}
};

// Should not print
/* Should not print */
if false {
if true {
print_string "one"
Expand Down Expand Up @@ -209,7 +209,7 @@ if printIfFirstArgGreater {
}
};

// Should Be Parsed As: Cleary a type error, but at least the parsing makes that clear
/* Should Be Parsed As: Cleary a type error, but at least the parsing makes that clear */
if printIfFirstArgGreater {
fun a b =>
if (a > b) {
Expand All @@ -227,7 +227,7 @@ fun a b =>
print_string "a > b"
};

// What you probably wanted was:
/* What you probably wanted was: */
if printIfFirstArgGreater {
fun a b =>
if (a > b) {
Expand All @@ -240,7 +240,7 @@ if printIfFirstArgGreater {
}
};

// Mutative if statement: Not used to evaluate to something.
/* Mutative if statement: Not used to evaluate to something. */
if (10 < 100) {
let msg = "If there was any doubt, 10 is in fact less than 100.";
print_string msg
Expand All @@ -266,12 +266,12 @@ let x: int = 10;

let x: int = (10: int);

// let (x:int) = (10:string);
// let (x:string) = ("hello":int);
/* let (x:int) = (10:string); */
/* let (x:string) = ("hello":int); */
/** TUPLES
*============================================================================
*/
// In Reason, types look like the data they model! Tuples are no exception.
/* In Reason, types look like the data they model! Tuples are no exception. */
type pairOfInts = (int, int);

let letBindingWithTypeConstraint: int = 10;
Expand All @@ -281,22 +281,22 @@ let (tupleItem: int, withTypeConstraint: int) = (
20
);

// To make sure that tuple field annotations are annotating the entire field
/* To make sure that tuple field annotations are annotating the entire field */
let _dummyFunc x => 10;

let annotatingFuncApplication = (
_dummyFunc "a": int,
_dummyFunc "a": int
);

// Pretty printer might stick the [int] at the label.
/* Pretty printer might stick the [int] at the label. */
let annotatingSingleFuncApplication: int = _dummyFunc "a";

// So lets try a place where it won't
/* So lets try a place where it won't */
let annotatingSingleFuncApplication = {
// Commenting a let binding.
/* Commenting a let binding. */
let a = 100;
// Commenting another let binding.
/* Commenting another let binding. */
let int = 200;
/*
* This demonstrates why named arguments cannot simply have the form (func
Expand Down Expand Up @@ -324,31 +324,31 @@ let (tupleItem, withOutsideTypeConstraint): (
/** Immutable Lists
* ============================================================================
*/
// Anatomy: -Head- --------- Tail--------- nil: You can't see nil
/* Anatomy: -Head- --------- Tail--------- nil: You can't see nil */
let x: list int = [1, 2, 3, 4, 5, 6, 7, 8, 9];

let hd = "appendedToHead";

let tl = ["listTo", "append", "to"];

// To push *one* and only *one* item to the front of a list - use [hd, ...tl]
/* To push *one* and only *one* item to the front of a list - use [hd, ...tl] */
let result: list string = [hd, ...tl];

// Is the same as writing
/* Is the same as writing */
let result: list string = [
"appendedToHead",
"listTo",
"append",
"to"
];

// To operate on lists, use pattern matching
/* To operate on lists, use pattern matching */
let rec size =
fun
| [] => 0
| [hd, ...tl] => 1 + size tl;

// Optimize for tail recursion
/* Optimize for tail recursion */
let rec size soFar lst =>
switch lst {
| [] => 0
Expand Down Expand Up @@ -410,15 +410,15 @@ let MyThing _ as ppp | YourThing _ as ppp = ppp;
* But this isn't needed in Reason because OR patterns have much lower
* precedence - they should be pretty printed in the same way.
*/
// TODO:
// let rec nestedMatch lstLst => match lstLst with {
// hd::tl: match tl with {
// []: 0 + 0,
// tlHd::tlTl: 0 + 1,
// },
// []: 0
// };
//
/* TODO: */
/* let rec nestedMatch lstLst => match lstLst with { */
/* hd::tl: match tl with { */
/* []: 0 + 0, */
/* tlHd::tlTl: 0 + 1, */
/* }, */
/* []: 0 */
/* }; */
/* */
/** ARRAYS
* ============================================================================
* Arrays are weird looking. Usually you want lists because they support pattern
Expand All @@ -433,11 +433,11 @@ let arrayWithTwo = [|10, 10|];

let secondItem = arrayWithTwo.(1);

// Getting And Setting: Yeah, we should really change this
// Get an array item at index 1
/* Getting And Setting: Yeah, we should really change this */
/* Get an array item at index 1 */
let secondItem = arrayWithTwo.(1);

// Set an array item at index 1
/* Set an array item at index 1 */
arrayWithTwo.(1) = 300;

/**
Expand All @@ -447,7 +447,7 @@ arrayWithTwo.(1) = 300;
*/
let myString = "asdf";

// Replacing a character: I could do without this sugar
/* Replacing a character: I could do without this sugar */
myString.[2] = '9';

/* FUNCTIONS
Expand All @@ -460,20 +460,20 @@ let one = 900;

let two = 10000;

// Tuple expressions can be annotated without additional paren wrapping
/* Tuple expressions can be annotated without additional paren wrapping */
let myTuple = (one: int, two: int);

type myTupleType = (int, int);

let myTuple: myTupleType = myTuple;

// Anything *outside* of a tuple, must still be annotated within parens.
/* Anything *outside* of a tuple, must still be annotated within parens. */
let myTuple: myTupleType = (one: int, two: int);

// Now functions that accept a single argument being a tuple look familiar
/* Now functions that accept a single argument being a tuple look familiar */
let addValues (a: int, b: int) => a + b;

// Impossible to annotate return values of fun lambdas - just like in OCaml
/* Impossible to annotate return values of fun lambdas - just like in OCaml */
let addValues (a: int, b: int) => a + b;

let functionReturnValueType
Expand All @@ -489,7 +489,7 @@ let curriedFormTwo (i: int, x: int) :(int, int) => (
x
);

// let nonCurriedFormTwo = fun (i:int, x:int) (:(int, int)) => (i, x);
/* let nonCurriedFormTwo = fun (i:int, x:int) (:(int, int)) => (i, x); */
let curriedFormThree
(i: int, (a: int, b: int): (int, int))
:(int, int, int) => (
Expand All @@ -498,7 +498,7 @@ let curriedFormThree
b
);

// let nonCurriedFormThree = fun (i:int, (a:int, b:int):(int, int)) (:(int, int, int)) => (i, a, b);
/* let nonCurriedFormThree = fun (i:int, (a:int, b:int):(int, int)) (:(int, int, int)) => (i, a, b); */
/** TODO: But this, however doesn't work.
* let (myCurriedFunc: int => int) a => a;
* Note: This is likely because only "simple patterns" are accepted as constraints
Expand Down
32 changes: 17 additions & 15 deletions formatTest/unit_tests/expected_output/comments.re
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,17 @@ let testPostComment = "";
let testMultiline a =>
switch a {
// single line comment
| `Thingy x => {
print_string
/* multiline comment should be fine */
"matched thingy x";
let zz = 10;
// post line single line comment
zz
}
| `Other x => {
// single line comment above
print_string "matched other x";
x
}
| `Thingy x =>
print_string
/* multiline comment should be fine */
"matched thingy x";
let zz = 10;
// post line single line comment
zz
| `Other x =>
// single line comment above
print_string "matched other x";
x
};

// single line comment below
Expand Down Expand Up @@ -66,14 +64,18 @@ let a = 10;
let b = 20;

/*A*/
let named /* a::a */ a::a /* b::b */ b::b => /* a + b */ a + b;
let named /* a::a */ a::a /* b::b */ b::b =>
/* a + b */
a + b;

/*B*/
let namedAlias
/* a::aa */
a::aa
/* b::bb */
b::bb => /* aa + bb */ aa + bb;
b::bb =>
/* aa + bb */
aa + bb;

/*C*/
let namedAnnot
Expand Down
Loading

0 comments on commit 4dbb917

Please sign in to comment.