Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion debug/org.eclipse.debug.tests/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,11 @@ Export-Package: org.eclipse.debug.tests,
Import-Package: org.assertj.core.api;version="3.24.2",
org.assertj.core.api.iterable,
org.junit.jupiter.api;version="[5.14.0,6.0.0)",
org.junit.jupiter.api.io;version="[5.14.0,6.0.0)",
org.junit.jupiter.api.extension;version="[5.14.0,6.0.0)",
org.junit.jupiter.api.function;version="[5.14.0,6.0.0)",
org.junit.jupiter.api.io;version="[5.14.0,6.0.0)",
org.junit.jupiter.params;version="[5.14.0,6.0.0)",
org.junit.jupiter.params.provider;version="[5.14.0,6.0.0)",
org.junit.platform.suite.api;version="[1.14.0,2.0.0)",
org.opentest4j;version="[1.3.0,2.0.0)"
Eclipse-BundleShape: dir
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@
import org.eclipse.debug.tests.breakpoint.BreakpointTests;
import org.eclipse.debug.tests.breakpoint.SerialExecutorTest;
import org.eclipse.debug.tests.console.ConsoleDocumentAdapterTests;
import org.eclipse.debug.tests.console.ConsoleShowHideTests;
import org.eclipse.debug.tests.console.ConsoleManagerTests;
import org.eclipse.debug.tests.console.ConsoleOutputLineTruncateTest;
import org.eclipse.debug.tests.console.ConsoleOutputLineWrapTest;
import org.eclipse.debug.tests.console.ConsoleShowHideTests;
import org.eclipse.debug.tests.console.ConsoleTests;
import org.eclipse.debug.tests.console.FileLinkTests;
import org.eclipse.debug.tests.console.IOConsoleFixedWidthTests;
Expand Down Expand Up @@ -122,6 +124,8 @@
ConsoleManagerTests.class, //
ConsoleTests.class, //
IOConsoleTests.class, //
ConsoleOutputLineWrapTest.class, //
ConsoleOutputLineTruncateTest.class, //
IOConsoleFixedWidthTests.class, //
ProcessConsoleManagerTests.class, //
ProcessConsoleTests.class, //
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
/*******************************************************************************
* Copyright (c) 2026 Simeon Andreev and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Simeon Andreev - initial API and implementation
*******************************************************************************/
package org.eclipse.debug.tests.console;

import static org.junit.jupiter.api.Assertions.assertEquals;

import java.util.Arrays;
import java.util.stream.Stream;

import org.eclipse.ui.internal.console.ConsoleOutputLineTruncate;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;

/**
* Tests {@link ConsoleOutputLineTruncate} handling chunks of input, breaking
* input lines at a specific length limit.
*/
public class ConsoleOutputLineTruncateTest {

/**
* Parameters of a test for {@link ConsoleOutputLineTruncate}.
*
* @param limit the line length limit for the test
* @param chunks how many times the {@code input} is repeated
* @param repeat how many times {@code output} is repeated in the expected
* output, line breaks are inserted between concatenated
* {@code output}
* @param input input string passed to the tested
* {@link ConsoleOutputLineTruncate}
* @param output expected output, repeated {@code repeat} times
* @param nl the newline character sequence
*/
record Parameters(int limit, int chunks, int repeat, String input, String output, String nl) {
}

private static Parameters test(int limit, String input, String output, String nl) {
return test(limit, 1, 1, input, output, nl);
}

private static Parameters test(int limit, int chunks, int repeat, String input, String output, String nl) {
return new Parameters(limit, chunks, repeat, input, output, nl);
}

private static final Parameters[] TESTS = {
// Unix newlines
test(4, "\n========", "\n==== ...\n", "\n"),
test(10, "========", "========", "\n"),
test(10, 10, 1, "========", "========== ...\n", "\n"),
test(4, "========", "==== ...\n", "\n"),
test(4, 10, 1, "========", "==== ...\n", "\n"),
test(4, "====\n====", "====\n====", "\n"),
test(4, 5, 1, "====\n====", "====\n==== ...\n==== ...\n==== ...\n==== ...\n====", "\n"),
test(2, 5, 1, "=======\n==", "== ...\n== ...\n== ...\n== ...\n== ...\n==", "\n"),
test(2, "====\n====", "== ...\n== ...\n", "\n"),
test(2, 5, 1, "====\n====", "== ...\n== ...\n== ...\n== ...\n== ...\n== ...\n", "\n"),
test(2, "=========", "== ...\n", "\n"),
test(2, "=======\n==", "== ...\n==", "\n"),
test(3, "=========", "=== ...\n", "\n"),
test(3, 5, 1, "=========", "=== ...\n", "\n"),
test(3, "========\n=", "=== ...\n=", "\n"),
test(2, "======\n======", "== ...\n== ...\n", "\n"),
test(2, 5, 1, "======\n======", "== ...\n== ...\n== ...\n== ...\n== ...\n== ...\n", "\n"),
test(3, 3, 1, "========\n=", "=== ...\n=== ...\n=== ...\n=" , "\n"),
test(4, 3, 1, "========\n=", "==== ...\n==== ...\n==== ...\n=", "\n"),

// Windows newlines
test(4, "\r\n========", "\r\n==== ...\r\n", "\r\n"),
test(10, "========", "========", "\r\n"),
test(10, 10, 1, "========", "========== ...\r\n", "\r\n"),
test(4, "========", "==== ...\r\n", "\r\n"),
test(4, 10, 1, "========", "==== ...\r\n", "\r\n"),
test(4, "====\r\n====", "====\r\n====", "\r\n"),
test(4, 5, 1, "====\r\n====", "====\r\n==== ...\r\n==== ...\r\n==== ...\r\n==== ...\r\n====", "\r\n"),
test(2, 5, 1, "=======\r\n==", "== ...\r\n== ...\r\n== ...\r\n== ...\r\n== ...\r\n==", "\r\n"),
test(2, "====\r\n====", "== ...\r\n== ...\r\n", "\r\n"),
test(2, 5, 1, "====\r\n====", "== ...\r\n== ...\r\n== ...\r\n== ...\r\n== ...\r\n== ...\r\n", "\r\n"),
test(2, "=========", "== ...\r\n", "\r\n"),
test(2, "=======\r\n==", "== ...\r\n==", "\r\n"),
test(3, "=========", "=== ...\r\n", "\r\n"),
test(3, 5, 1, "=========", "=== ...\r\n", "\r\n"),
test(3, "========\r\n=", "=== ...\r\n=", "\r\n"),
test(2, "======\r\n======", "== ...\r\n== ...\r\n", "\r\n"),
test(2, 5, 1, "======\r\n======", "== ...\r\n== ...\r\n== ...\r\n== ...\r\n== ...\r\n== ...\r\n", "\r\n"),
test(3, 3, 1, "========\r\n=", "=== ...\r\n=== ...\r\n=== ...\r\n=", "\r\n"),
test(4, 3, 1, "========\r\n=", "==== ...\r\n==== ...\r\n==== ...\r\n=", "\r\n"),
};

private static Stream<Arguments> tests() {
return Arrays.stream(TESTS).map(Arguments::of);
}

@ParameterizedTest
@MethodSource("tests")
public void test(Parameters p) {
ConsoleOutputLineTruncate truncate = new ConsoleOutputLineTruncate(p.nl);
StringBuilder c = new StringBuilder();
for (int i = 0; i < p.chunks; ++i) {
StringBuilder s = new StringBuilder(p.input);
CharSequence text = truncate.modify(s, p.limit);
c.append(text);
}
String expected = repeat(p.output, p.repeat, p.nl);
assertEquals(expected, c.toString());
}

private static String repeat(String s, int r, String nl) {
return (nl + s).repeat(r).substring(nl.length());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
/*******************************************************************************
* Copyright (c) 2026 Simeon Andreev and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Simeon Andreev - initial API and implementation
*******************************************************************************/
package org.eclipse.debug.tests.console;

import static org.junit.jupiter.api.Assertions.assertEquals;

import java.util.Arrays;
import java.util.stream.Stream;

import org.eclipse.ui.internal.console.ConsoleOutputLineWrap;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;

/**
* Tests {@link ConsoleOutputLineWrap} handling chunks of input, breaking input
* lines at a specific length limit.
*/
public class ConsoleOutputLineWrapTest {

/**
* Parameters of a test for {@link ConsoleOutputLineWrap}.
*
* @param limit the line length limit for the test
* @param chunks how many times the {@code input} is repeated
* @param repeat how many times {@code output} is repeated in the expected
* output, line breaks are inserted between concatenated
* {@code output}
* @param input input string passed to the tested
* {@link ConsoleOutputLineWrap}
* @param output expected output, repeated {@code repeat} times
* @param nl the newline character sequence
*/
record Parameters(int limit, int chunks, int repeat, String input, String output, String nl) {
}

private static Parameters test(int limit, String input, String output, String nl) {
return test(limit, 1, 1, input, output, nl);
}

private static Parameters test(int limit, int chunks, String input, String output, String nl) {
return test(limit, chunks, chunks, input, output, nl);
}

private static Parameters test(int limit, int chunks, int repeat, String input, String output, String nl) {
return new Parameters(limit, chunks, repeat, input, output, nl);
}

private static final Parameters[] TESTS = {
// Unix newlines
test(4, "\n========", "\n====\n====", "\n"),

test(10, "========" , "========" , "\n"),
test(10, 10, 8, "========" , "==========", "\n"),
test( 4, "========" , "====\n====", "\n"),
test( 4, 10, "========" , "====\n====", "\n"),
test( 4, "====\n====" , "====\n====", "\n"),
test( 4, 10, "====\n====" , "====\n====", "\n"),

test( 2, 10, "=======\n==" , "==\n==\n==\n=\n==", "\n"),
test( 2, "====\n====" , "==\n==\n==\n==" , "\n"),
test( 2, 10, "====\n====" , "==\n==\n==\n==" , "\n"),
test( 2, "=========" , "==\n==\n==\n==\n=", "\n"),
test( 2, "=======\n==" , "==\n==\n==\n=\n==", "\n"),
test( 3, "=========" , "===\n===\n===" , "\n"),
test( 3, 10, "=========" , "===\n===\n===" , "\n"),
test( 3, "========\n=" , "===\n===\n==\n=" , "\n"),

test( 2, "======\n======", "==\n==\n==\n==\n==\n==", "\n"),
test( 2, 10, "======\n======", "==\n==\n==\n==\n==\n==", "\n"),

test( 3, 3, 1, "========\n=" , "===\n===\n==\n===\n===\n===\n===\n===\n===\n=", "\n"),
test( 4, 3, 1, "========\n=" , "====\n====\n====\n====\n=\n====\n====\n=\n=" , "\n"),

// Windows newlines
test(4, "\r\n========", "\r\n====\r\n====", "\r\n"),

test(10, "========" , "========" , "\r\n"),
test(10, 10, 8, "========" , "==========" , "\r\n"),
test( 4, "========" , "====\r\n====", "\r\n"),
test( 4, 10, "========" , "====\r\n====", "\r\n"),
test( 4, "====\r\n====" , "====\r\n====", "\r\n"),
test( 4, 10, "====\r\n====" , "====\r\n====", "\r\n"),

test( 2, 10, "=======\r\n==" , "==\r\n==\r\n==\r\n=\r\n==", "\r\n"),
test( 2, "====\r\n====" , "==\r\n==\r\n==\r\n==" , "\r\n"),
test( 2, 10, "====\r\n====" , "==\r\n==\r\n==\r\n==" , "\r\n"),
test( 2, "=========" , "==\r\n==\r\n==\r\n==\r\n=", "\r\n"),
test( 2, "=======\r\n==" , "==\r\n==\r\n==\r\n=\r\n==", "\r\n"),
test( 3, "=========" , "===\r\n===\r\n===" , "\r\n"),
test( 3, 10, "=========" , "===\r\n===\r\n===" , "\r\n"),
test( 3, "========\r\n=" , "===\r\n===\r\n==\r\n=" , "\r\n"),

test( 2, "======\r\n======", "==\r\n==\r\n==\r\n==\r\n==\r\n==", "\r\n"),
test( 2, 10, "======\r\n======", "==\r\n==\r\n==\r\n==\r\n==\r\n==", "\r\n"),

test( 3, 3, 1, "========\r\n=" , "===\r\n===\r\n==\r\n===\r\n===\r\n===\r\n===\r\n===\r\n===\r\n=", "\r\n"),
test( 4, 3, 1, "========\r\n=" , "====\r\n====\r\n====\r\n====\r\n=\r\n====\r\n====\r\n=\r\n=" , "\r\n"),
};

private static Stream<Arguments> tests() {
return Arrays.stream(TESTS).map(Arguments::of);
}

@ParameterizedTest
@MethodSource("tests")
public void test(Parameters p) {
ConsoleOutputLineWrap lineBreak = new ConsoleOutputLineWrap(p.nl);
StringBuilder c = new StringBuilder();
for (int i = 0; i < p.chunks; ++i) {
StringBuilder s = new StringBuilder(p.input);
CharSequence text = lineBreak.modify(s, p.limit);
c.append(text);
}
String expected = repeat(p.output, p.repeat, p.nl);
assertEquals(expected, c.toString());
}

private static String repeat(String s, int r, String nl) {
return (nl + s).repeat(r).substring(nl.length());
}
}
Loading
Loading