GRAILS-1019: Allowing expressions to be used with the 'disabled' attribute for g...
[grails.git] / test / groovy / org / codehaus / groovy / grails / web / taglib / FormatTagLibTests.groovy
blobec257615a53fe41de5b3f6fe5ee41c6d2c2f31c4
1 /**
2 * Tests for the FormatTagLib.
4 * @author Graeme Rocher
5 * @since 0.6
7 * Created: Jul 25, 2007
8 * Time: 7:57:59 AM
9 *
12 package org.codehaus.groovy.grails.web.taglib
14 class FormatTagLibTests extends AbstractGrailsTagTests {
16 void testFormatDate() {
17 def calender = new GregorianCalendar(1980,1,3)
18 def template = '<g:formatDate format="yyyy-MM-dd" date="${date}"/>'
19 assertOutputEquals("1980-02-03", template, [date:calender.getTime()])
22 void testFormatDateNullDate() {
23 def template = '<g:formatDate format="yyyy-MM-dd" date="${date}"/>'
24 assertOutputEquals("", template, [date:null])
27 void testFormatDateCurrentDate() {
28 def template = '<g:formatDate format="yyyy-MM-dd"/>'
29 def output = applyTemplate(template)
30 assertTrue(output ==~ /\d{4}-\d{2}-\d{2}/)
33 void testFormatNumber() {
34 def template = '<g:formatNumber number="${myNumber}" format="\\$###,##0"/>'
35 assertOutputEquals('$10', template, [myNumber:10])
38 void testFormatNumberNullNumber() {
39 def template = '<g:formatNumber number="${myNumber}"/>'
40 assertOutputEquals("", template, [myNumber:null])
43 void testFormatNumberNoNumber() {
44 try
46 applyTemplate('<g:formatNumber/>')
47 fail('Expecting a GrailsTagException')
49 catch(org.codehaus.groovy.grails.web.taglib.exceptions.GrailsTagException e)
51 // expected
55 void testFormatDateFromBundle() {
56 def calender = new GregorianCalendar(1980,1,3)
57 def template = '<g:formatDate formatName="format.date" date="${date}"/>'
58 messageSource.addMessage("format.date", request.locale, "yyyy-MM-dd")
60 assertOutputEquals("1980-02-03", template, [date:calender.getTime()])
63 void testFormatNumberFromBundle() {
64 def template = '<g:formatNumber number="${myNumber}" formatName="format.number" />'
65 messageSource.addMessage("format.number", request.locale, '\$###,##0')
66 assertOutputEquals('$10', template, [myNumber:10])
69 void testEncodeAs() {
70 def template = '<g:encodeAs codec="HTML">Coheed & Cambria</g:encodeAs>'
72 assertOutputEquals('Coheed &amp; Cambria', template, [:])