rust/tests/source/expr.rs

244 lines
5.5 KiB
Rust
Raw Normal View History

// Test expressions
fn foo() -> bool {
2015-07-23 23:08:41 +02:00
let boxed: Box<i32> = box 5;
2015-08-21 13:31:09 +02:00
let referenced = &5 ;
2015-07-23 23:08:41 +02:00
let very_long_variable_name = ( a + first + simple + test );
let very_long_variable_name = (a + first + simple + test + AAAAAAAAAAAAA + BBBBBBBBBBBBBBBBB + b + c);
2015-07-24 15:29:04 +02:00
let is_internalxxxx = self.codemap.span_to_filename(s) == self.codemap.span_to_filename(m.inner);
let some_val = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa * bbbb / (bbbbbb -
function_call(x, *very_long_pointer, y))
2015-08-21 13:31:09 +02:00
+ 1000 ;
some_ridiculously_loooooooooooooooooooooong_function(10000 * 30000000000 + 40000 / 1002200000000
- 50000 * sqrt(-1),
2015-07-03 00:50:55 +02:00
trivial_value);
(((((((((aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + a +
2015-08-21 13:31:09 +02:00
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + aaaaa))))))))) ;
2015-07-19 23:42:54 +02:00
2015-07-20 23:29:25 +02:00
{ for _ in 0..10 {} }
{{{{}}}}
2015-07-19 23:42:54 +02:00
if 1 + 2 > 0 { let result = 5; result } else { 4};
2015-07-19 22:25:44 +02:00
if let Some(x) = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa {
// Nothing
}
if let Some(x) = (aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) {}
if let (some_very_large,
tuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuple) = 1
+ 2 + 3 {
}
if let (some_very_large,
tuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuple) = 1111 + 2222 {}
2015-07-20 23:29:25 +02:00
if let (some_very_large, tuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuple) = 1
+ 2 + 3 {
}
let test = if true { 5 } else { 3 };
2015-07-19 23:42:54 +02:00
if cond() {
something();
} else if different_cond() {
something_else();
} else {
// Check subformatting
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
}
}
2015-07-20 23:29:25 +02:00
fn bar() {
let range = ( 111111111 + 333333333333333333 + 1111 + 400000000000000000) .. (2222 + 2333333333333333);
let another_range = 5..some_func( a , b /* comment */);
for _ in 1 ..{ call_forever(); }
syntactically_correct(loop { sup( '?'); }, if cond { 0 } else { 1 });
let third = ..10;
2015-08-21 13:31:09 +02:00
let infi_range = .. ;
2015-07-20 23:29:25 +02:00
let foo = 1..;
2015-08-21 13:31:09 +02:00
let bar = 5 ;
2015-07-20 23:29:25 +02:00
let nonsense = (10 .. 0)..(0..10);
2015-07-25 23:28:31 +02:00
2015-09-03 20:15:24 +02:00
loop{if true {break}}
2015-07-25 23:28:31 +02:00
let x = (aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa &&
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,
a);
}
2015-08-01 14:22:31 +02:00
fn baz() {
unsafe /* {}{}{}{{{{}} */ {
let foo = 1u32;
}
unsafe /* very looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong comment */ {}
unsafe // So this is a very long comment.
// Multi-line, too.
// Will it still format correctly?
{
}
unsafe {
// Regular unsafe block
}
2015-09-05 08:26:28 +02:00
unsafe {
foo()
}
unsafe {
foo();
}
2015-08-01 14:22:31 +02:00
}
2015-08-16 06:13:55 +02:00
// Test some empty blocks.
fn qux() {
{}
// FIXME this one could be done better.
{ /* a block with a comment */ }
{
}
{
// A block with a comment.
}
}
fn issue227() {
{
let handler = box DocumentProgressHandler::new(addr, DocumentProgressTask::DOMContentLoaded);
}
}
fn issue184(source: &str) {
for c in source.chars() {
if index < 'a' {
continue;
}
}
}
2015-09-12 00:06:17 +02:00
2015-09-22 03:27:52 +02:00
fn matches() {
match 1 {
1 => 1, // foo
2 => 2,
// bar
3 => 3,
_ => 0 // baz
}
}
2015-09-24 02:22:06 +02:00
fn issue339() {
match a {
b => {}
c => { }
d => {
}
e => {
}
// collapsing here is safe
ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff => {
}
// collapsing here exceeds line length
ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffg => {
}
h => { // comment above block
}
i => {
} // comment below block
j => {
// comment inside block
}
j2 => {
// comments inside...
} // ... and after
// TODO uncomment when vertical whitespace is handled better
// k => {
//
// // comment with WS above
// }
// l => {
// // comment with ws below
//
// }
m => {
} n => { } o =>
{
}
p => { // Dont collapse me
} q => { } r =>
{
}
s => 0, // s comment
// t comment
t => 1,
u => 2,
// TODO uncomment when block-support exists
// v => {
// } /* funky block
// * comment */
// final comment
}
}
2015-09-12 00:06:17 +02:00
fn arrays() {
let x = [0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
0,
7,
8,
9,
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
0];
let y = [/* comment */ 1, 2 /* post comment */, 3];
let z = [xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx, yyyyyyyyyyyyyyyyyyyyyyyyyyy, zzzzzzzzzzzzzzzzzz, q];
[ 1 + 3, 4 , 5, 6, 7, 7, fncall::<Vec<_>>(3-1)]
}