Skip to content

Commit

Permalink
ch2
Browse files Browse the repository at this point in the history
  • Loading branch information
demian0311 committed May 14, 2012
1 parent 1ce396c commit 93bea6c
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 0 deletions.
10 changes: 10 additions & 0 deletions groovy_in_action/chapter2/Book.groovy
@@ -0,0 +1,10 @@
class Book{
private String title
Book(String theTitle){
title = theTitle
}

String getTitle(){
return title
}
}
35 changes: 35 additions & 0 deletions groovy_in_action/chapter2/chapter2.groovy
@@ -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+/

12 changes: 12 additions & 0 deletions groovy_in_action/customers.xml
@@ -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>

0 comments on commit 93bea6c

Please sign in to comment.