Skip to content

Commit

Permalink
Convert groovy source files to java
Browse files Browse the repository at this point in the history
  • Loading branch information
gnodet committed May 25, 2018
1 parent 2bf4058 commit 14c87f4
Show file tree
Hide file tree
Showing 10 changed files with 496 additions and 542 deletions.
32 changes: 0 additions & 32 deletions style/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,36 +49,4 @@
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<dependencies>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-eclipse-compiler</artifactId>
<version>2.9.2-01</version>
</dependency>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-eclipse-batch</artifactId>
<version>2.4.3-01</version>
</dependency>
</dependencies>
<configuration>
<compilerId>groovy-eclipse-compiler</compilerId>
<showWarnings>true</showWarnings>
<compilerArgs>
<arg>-Xlint:all,-options</arg>
<!-- groovy-eclipse compiler does not support these options -->
<!--<arg>-Werror</arg>-->
<!--<arg>-profile</arg>-->
<!--<arg>compact1</arg>-->
</compilerArgs>
</configuration>
</plugin>
</plugins>
</build>

</project>

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
/*
* Copyright (c) 2002-2018, the original author or authors.
*
* This software is distributable under the BSD license. See the terms of the
* BSD license in the documentation provided with this software.
*
* http://www.opensource.org/licenses/bsd-license.php
*/
package org.jline.style;

import org.codehaus.groovy.runtime.DefaultGroovyMethods;
import org.jline.utils.AttributedString;
import org.junit.Test;

import static org.jline.utils.AttributedStyle.*;

/**
* Tests for {@link StyleBundleInvocationHandler}.
*/
public class StyleBundleInvocationHandlerTest extends StyleTestSupport {

@Test
public void bundleMissingStyleGroup() {
try {
StyleBundleInvocationHandler.create(source, MissingStyleGroupStyles.class);
assert false;
} catch (StyleBundleInvocationHandler.InvalidStyleGroupException e) {
// expected
}

}

@Test
public void bundleProxyToString() {
Styles styles = StyleBundleInvocationHandler.create(source, Styles.class);
assert styles.toString().equals(Styles.class.getName());
}

@Test
public void bundleDefaultStyle() {
Styles styles = StyleBundleInvocationHandler.create(source, Styles.class);
AttributedString string = styles.boldRed("foo bar");
DefaultGroovyMethods.println(this, string.toAnsi());
assert string.equals(new AttributedString("foo bar", BOLD.foreground(RED)));
}

@Test
public void bundleDefaultStyleMissing() {
Styles styles = StyleBundleInvocationHandler.create(source, Styles.class);
try {
styles.missingDefaultStyle("foo bar");
assert false;
} catch (StyleBundleInvocationHandler.StyleBundleMethodMissingDefaultStyleException e) {
// expected
}

}

@Test
public void bundleDefaultStyleMissingButSourceReferenced() {
source.set("test", "missingDefaultStyle", "bold");
Styles styles = StyleBundleInvocationHandler.create(source, Styles.class);
AttributedString string = styles.missingDefaultStyle("foo bar");
DefaultGroovyMethods.println(this, string.toAnsi());
assert string.equals(new AttributedString("foo bar", BOLD));
}

@Test
public void bundleStyleNameWithDefaultStyle() {
Styles styles = StyleBundleInvocationHandler.create(source, Styles.class);
AttributedString string = styles.boldRedObjectWithStyleName("foo bar");
DefaultGroovyMethods.println(this, string.toAnsi());
assert string.equals(new AttributedString("foo bar", BOLD.foreground(RED)));
}

@Test
public void bundleSourcedStyle() {
source.set("test", "boldRed", "bold,fg:yellow");
Styles styles = StyleBundleInvocationHandler.create(source, Styles.class);
AttributedString string = styles.boldRed("foo bar");
DefaultGroovyMethods.println(this, string.toAnsi());
assert string.equals(new AttributedString("foo bar", BOLD.foreground(YELLOW)));
}

@Test
public void bundleExplicitStyleGroup() {
source.set("test2", "boldRed", "bold,fg:yellow");
Styles styles = StyleBundleInvocationHandler.create(new StyleResolver(source, "test2"), Styles.class);
AttributedString string = styles.boldRed("foo bar");
DefaultGroovyMethods.println(this, string.toAnsi());
assert string.equals(new AttributedString("foo bar", BOLD.foreground(YELLOW)));
}

@Test
public void bundleMethodValidation() {
Styles styles = StyleBundleInvocationHandler.create(source, Styles.class);

try {
styles.invalidReturn("foo");
assert false;
} catch (StyleBundleInvocationHandler.InvalidStyleBundleMethodException e) {
// expected
}


try {
styles.notEnoughArguments();
assert false;
} catch (StyleBundleInvocationHandler.InvalidStyleBundleMethodException e) {
// expected
}


try {
styles.tooManyArguments(1, 2);
assert false;
} catch (StyleBundleInvocationHandler.InvalidStyleBundleMethodException e) {
// expected
}

}

@StyleBundle.StyleGroup("test")
public interface Styles extends StyleBundle {

@DefaultStyle("bold,fg:red")
AttributedString boldRed(String value);

@StyleName("boldRed")
@DefaultStyle("bold,fg:red")
AttributedString boldRedObjectWithStyleName(Object value);

AttributedString missingDefaultStyle(String value);

void invalidReturn(String value);

AttributedString notEnoughArguments();

AttributedString tooManyArguments(int a, int b);
}

public interface MissingStyleGroupStyles extends StyleBundle {

@DefaultStyle("bold,fg:red")
AttributedString boldRed(String value);
}
}

0 comments on commit 14c87f4

Please sign in to comment.