This repository has been archived by the owner on Sep 28, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #337 from danielpetisme/fix/ansi-cursor
Fix cursor movement
- Loading branch information
Showing
3 changed files
with
82 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
* Copyright (c) 2012-2015 Institut National des Sciences Appliquées de Lyon (INSA-Lyon) | ||
* | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
*/ | ||
|
||
package gololang; | ||
|
||
import org.hamcrest.Matchers; | ||
import org.testng.SkipException; | ||
import org.testng.annotations.BeforeMethod; | ||
import org.testng.annotations.Test; | ||
|
||
import java.io.ByteArrayOutputStream; | ||
import java.io.IOException; | ||
import java.io.OutputStream; | ||
import java.io.PrintStream; | ||
import java.lang.reflect.Method; | ||
|
||
import static org.eclipse.golo.internal.testing.TestUtils.compileAndLoadGoloModule; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.is; | ||
|
||
public class AnsiCodesTest { | ||
|
||
private static final String SRC = "src/test/resources/for-test/"; | ||
private Class<?> moduleClass; | ||
|
||
private StringOutputStream out; | ||
|
||
public static class StringOutputStream extends OutputStream { | ||
|
||
private StringBuilder buffer = new StringBuilder(); | ||
|
||
@Override | ||
public void write(int b) throws IOException { | ||
buffer.append((char)b); | ||
} | ||
|
||
public String getString() { | ||
return buffer.toString(); | ||
} | ||
} | ||
|
||
@BeforeMethod | ||
public void load_module() throws Throwable { | ||
if (System.getenv("golo.bootstrapped") == null) { | ||
throw new SkipException("Golo is in a bootstrap build execution"); | ||
} | ||
moduleClass = compileAndLoadGoloModule(SRC, "ansicodes.golo"); | ||
out = new StringOutputStream(); | ||
System.setOut(new PrintStream(out)); | ||
} | ||
|
||
@Test | ||
public void cursor_movement() throws Throwable { | ||
Method cursor_movement = moduleClass.getMethod("cursor_movement"); | ||
cursor_movement.invoke(null); | ||
assertThat(out.getString(), is("\u001B[2C\u001B[10A\u001B[5D\u001B[3B")); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# ............................................................................................... # | ||
|
||
module golo.test.bootstrapped.JSON | ||
|
||
import gololang.AnsiCodes | ||
|
||
# ............................................................................................... # | ||
|
||
function cursor_movement = { | ||
cursor_forward(2) | ||
cursor_up(10) | ||
cursor_backward(5) | ||
cursor_down(3) | ||
} |