Skip to content
Permalink
Browse files
GROOVY-10612: Tweak plus operation for Map instance to align with Java
  • Loading branch information
daniellansun committed May 2, 2022
1 parent 469e4d0 commit 8802d4d9aba7d9b13fda3ef8eb4a1f786b8351b2
Showing 2 changed files with 80 additions and 0 deletions.
@@ -24,6 +24,7 @@
import groovy.lang.DelegatingMetaClass;
import groovy.lang.EmptyRange;
import groovy.lang.ExpandoMetaClass;
import groovy.lang.GString;
import groovy.lang.GroovyObject;
import groovy.lang.GroovyRuntimeException;
import groovy.lang.GroovySystem;
@@ -15668,6 +15669,38 @@ public static Number plus(Character left, Character right) {
return plus(Integer.valueOf(left), right);
}

/**
* Appends a String to the literal of the Map instance.
*
* <pre class="groovyTestCase">
* assert '[a:1] is a map' == [a:1] + ' is a map'
* </pre>
*
* @param left a Map
* @param right a String
* @return the concatenated string
* @since 4.0.3
*/
public static String plus(Map left, String right) {
return DefaultGroovyMethods.toString(left) + right;
}

/**
* Appends a GString to the literal of the Map instance.
*
* <pre class="groovyTestCase">
* assert '[a:1] is a map' == [a:1] + " is ${'a'} map"
* </pre>
*
* @param left a Map
* @param right a GString
* @return the concatenated string
* @since 4.0.3
*/
public static String plus(Map left, GString right) {
return DefaultGroovyMethods.toString(left) + right;
}

/**
* Compare a Character and a Number. The ordinal value of the Character
* is used in the comparison (the ordinal value is the unicode
@@ -0,0 +1,47 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package bugs

import groovy.transform.CompileStatic
import org.junit.Test

import static groovy.test.GroovyAssert.assertScript

@CompileStatic
class Groovy10612 {
@Test
void testStringConcatenationWithPlus() {
assertScript '''
assert '[a:1] is a map' == [a:1] + ' is a map'
assert '[a:1] is a map' == [a:1] + " is ${'a'} map"
'''
}

@Test
void testStringConcatenationWithPlus_CS() {
assertScript '''
@groovy.transform.CompileStatic
def m() {
assert '[a:1] is a map' == [a:1] + ' is a map'
assert '[a:1] is a map' == [a:1] + " is ${'a'} map"
}
m()
'''
}
}

0 comments on commit 8802d4d

Please sign in to comment.