/scalate-core/src/test/scala/org/fusesource/scalate/mustache/OptionTest.scala

http://github.com/scalate/scalate · Scala · 60 lines · 16 code · 7 blank · 37 comment · 0 complexity · ced0ddf3d5394e9ce001008c70083685 MD5 · raw file

  1. /**
  2. * Copyright (C) 2009-2011 the original author or authors.
  3. * See the notice.md file distributed with this work for additional
  4. * information regarding copyright ownership.
  5. *
  6. * Licensed under the Apache License, Version 2.0 (the "License");
  7. * you may not use this file except in compliance with the License.
  8. * You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. package org.fusesource.scalate.mustache
  19. /**
  20. * Copyright (C) 2009-2010 the original author or authors.
  21. * See the notice.md file distributed with this work for additional
  22. * information regarding copyright ownership.
  23. *
  24. * Licensed under the Apache License, Version 2.0 (the "License");
  25. * you may not use this file except in compliance with the License.
  26. * You may obtain a copy of the License at
  27. *
  28. * http://www.apache.org/licenses/LICENSE-2.0
  29. *
  30. * Unless required by applicable law or agreed to in writing, software
  31. * distributed under the License is distributed on an "AS IS" BASIS,
  32. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  33. * See the License for the specific language governing permissions and
  34. * limitations under the License.
  35. */
  36. import org.fusesource.scalate.TemplateTestSupport
  37. /**
  38. * @version $Revision: 1.1 $
  39. */
  40. class OptionTest extends TemplateTestSupport {
  41. test("Some is unwrapped") {
  42. assertMoustacheOutput("Hey James!", "Hey {{name}}!", Map("name" -> Some("James")))
  43. }
  44. test("None is treated like null") {
  45. assertMoustacheOutput("Hey !", "Hey {{name}}!", Map("name" -> None))
  46. }
  47. test("Some is treated like a collection of 1") {
  48. assertMoustacheOutput("Hey James!", "{{#person}}Hey {{name}}!{{/person}}", Map("person" -> Some(Map("name" -> "James"))))
  49. }
  50. test("None is treated like a collection of 0") {
  51. assertMoustacheOutput("", "{{#person}}Hey {{name}}!{{/person}}", Map("person" -> None))
  52. }
  53. }