From 11a43d701c79eaf4cf85ec21f4865aaed1639795 Mon Sep 17 00:00:00 2001 From: Havoc Pennington Date: Thu, 5 Apr 2012 15:57:25 -0400 Subject: [PATCH] add very basic ConcatenationTest for string concatenation --- .../config/impl/ConcatenationTest.scala | 84 +++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 config/src/test/scala/com/typesafe/config/impl/ConcatenationTest.scala diff --git a/config/src/test/scala/com/typesafe/config/impl/ConcatenationTest.scala b/config/src/test/scala/com/typesafe/config/impl/ConcatenationTest.scala new file mode 100644 index 00000000..b0d2a8b8 --- /dev/null +++ b/config/src/test/scala/com/typesafe/config/impl/ConcatenationTest.scala @@ -0,0 +1,84 @@ +/** + * Copyright (C) 2012 Typesafe Inc. + */ +package com.typesafe.config.impl + +import org.junit.Assert._ +import org.junit._ +import com.typesafe.config.ConfigValue +import com.typesafe.config.ConfigException +import com.typesafe.config.ConfigResolveOptions +import com.typesafe.config.Config +import com.typesafe.config.ConfigFactory + +class ConcatenationTest extends TestUtils { + + @Test + def noSubstitutionsStringConcat() { + val conf = parseConfig(""" a : true "xyz" 123 foo """).resolve() + assertEquals("true xyz 123 foo", conf.getString("a")) + } + + @Test + def trivialStringConcat() { + val conf = parseConfig(""" a : ${x}foo, x = 1 """).resolve() + assertEquals("1foo", conf.getString("a")) + } + + @Test + def twoSubstitutionsStringConcat() { + val conf = parseConfig(""" a : ${x}foo${x}, x = 1 """).resolve() + assertEquals("1foo1", conf.getString("a")) + } + + @Test + def stringConcatCannotSpanLines() { + val e = intercept[ConfigException.Parse] { + parseConfig(""" a : ${x} + foo, x = 1 """) + } + assertTrue("wrong exception: " + e.getMessage, + e.getMessage.contains("not be followed") && + e.getMessage.contains("','")) + } + + @Test + def noObjectsInStringConcat() { + val e = intercept[ConfigException.Parse] { + parseConfig(""" a : abc { x : y } """) + } + assertTrue("wrong exception: " + e.getMessage, + e.getMessage.contains("Expecting") && + e.getMessage.contains("'{'")) + } + + @Test + def noArraysInStringConcat() { + val e = intercept[ConfigException.Parse] { + parseConfig(""" a : abc { x : y } """) + } + assertTrue("wrong exception: " + e.getMessage, + e.getMessage.contains("Expecting") && + e.getMessage.contains("'{'")) + } + + @Test + def noObjectsSubstitutedInStringConcat() { + val e = intercept[ConfigException.WrongType] { + parseConfig(""" a : abc ${x}, x : { y : z } """).resolve() + } + assertTrue("wrong exception: " + e.getMessage, + e.getMessage.contains("not a list or object") && + e.getMessage.contains("OBJECT")) + } + + @Test + def noArraysSubstitutedInStringConcat() { + val e = intercept[ConfigException.WrongType] { + parseConfig(""" a : abc ${x}, x : [1,2] """).resolve() + } + assertTrue("wrong exception: " + e.getMessage, + e.getMessage.contains("not a list or object") && + e.getMessage.contains("LIST")) + } +}