Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1ce396c
commit 93bea6c
Showing
3 changed files
with
57 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,10 @@ | |||
class Book{ | |||
private String title | |||
Book(String theTitle){ | |||
title = theTitle | |||
} | |||
|
|||
String getTitle(){ | |||
return title | |||
} | |||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,35 @@ | |||
#!/usr/bin/env groovy | |||
|
|||
// Page37: Assertions | |||
assert(true) | |||
assert 1 == 1 // equality, not identity | |||
def x = 1 | |||
assert x == 1 | |||
|
|||
def y = 1; assert y == 1 | |||
|
|||
// Page43: Annotations for AST Transformations | |||
@Immutable class FixedBook { | |||
String title | |||
} | |||
|
|||
def gina = new FixedBook('Groovy in Action') | |||
def regina = new FixedBook(title: 'Groovy in Action') | |||
|
|||
assert gina.title == 'Groovy in Action' | |||
assert gina == regina | |||
|
|||
try { | |||
gina.title = "Ooop!" | |||
assert false, "should not reach here" | |||
} catch(ReadOnlyPropertyException e){ | |||
println("yep, threw the exception") | |||
} | |||
|
|||
// Page45: Regular Expressions | |||
// / the string you are searching | |||
// / find operator | |||
// // the regular expression | |||
assert '12345' =~ /\d+/ | |||
// FAILS: assert 'ABCDE' =~ /\d+/ | |||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,12 @@ | |||
<?xml version="1.0" ?> | |||
<customers> | |||
<corporate> | |||
<customer name="Bill Gates" company="Microsoft" /> | |||
<customer name="Steve Jobs" company="Apple" /> | |||
<customer name="Jonathan Schwartz" company="Sun" /> | |||
</corporate> | |||
<consumer> | |||
<customer name="John Doe" /> | |||
<customer name="Jane Doe" /> | |||
</consumer> | |||
</customers> |