-
Notifications
You must be signed in to change notification settings - Fork 219
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Kay Werndli
committed
Apr 23, 2024
1 parent
247d90b
commit 9912fe1
Showing
3 changed files
with
69 additions
and
2 deletions.
There are no files selected for viewing
66 changes: 66 additions & 0 deletions
66
console/src/test/java/org/jline/widget/TailTipWidgetsTest.java
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,66 @@ | ||
/* | ||
* Copyright (c) 2024, the original author(s). | ||
* | ||
* This software is distributable under the BSD license. See the terms of the | ||
* BSD license in the documentation provided with this software. | ||
* | ||
* https://opensource.org/licenses/BSD-3-Clause | ||
*/ | ||
package org.jline.widget; | ||
|
||
import java.io.ByteArrayInputStream; | ||
import java.io.ByteArrayOutputStream; | ||
import java.io.IOException; | ||
|
||
import org.jline.reader.LineReader; | ||
import org.jline.reader.impl.LineReaderImpl; | ||
import org.jline.terminal.Terminal; | ||
import org.jline.terminal.impl.DumbTerminal; | ||
import org.jline.utils.InfoCmp.Capability; | ||
import org.jline.utils.Status; | ||
import org.jline.widget.TailTipWidgets.TipType; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
public final class TailTipWidgetsTest { | ||
|
||
/** A simple extension of {@link DumbTerminal} doing the minimal amount of work so that a {@link Status} constructed | ||
* from it is "supported". */ | ||
private static final class SupportedDumbTerminal extends DumbTerminal { | ||
private SupportedDumbTerminal() throws IOException { | ||
super(new ByteArrayInputStream(new byte[0]), new ByteArrayOutputStream()); | ||
strings.put(Capability.change_scroll_region, ""); | ||
strings.put(Capability.save_cursor, ""); | ||
strings.put(Capability.restore_cursor, ""); | ||
strings.put(Capability.cursor_address, ""); | ||
} | ||
} | ||
|
||
/** Subclass of {@link Status} exposing the {@code supported} field. For testing only. */ | ||
private static final class TestStatus extends Status { | ||
private TestStatus(Terminal terminal) { | ||
super(terminal); | ||
} | ||
|
||
private boolean isSupported() { | ||
return supported; | ||
} | ||
} | ||
|
||
/** A dummy {@link LineReader} that's immediately resized to 0x0. */ | ||
private static final class ZeroSizeLineReader extends LineReaderImpl { | ||
private ZeroSizeLineReader(Terminal terminal) throws IOException { | ||
super(terminal); | ||
display.resize(0, 0); | ||
} | ||
} | ||
|
||
@Test | ||
public void enableTest() throws Exception { | ||
Terminal terminal = new SupportedDumbTerminal(); | ||
assertTrue(new TestStatus(terminal).isSupported()); | ||
LineReader reader = new ZeroSizeLineReader(terminal); | ||
new TailTipWidgets(reader, __ -> null, 1, TipType.COMBINED).enable(); | ||
} | ||
} |
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