Skip to content

Commit

Permalink
IO.print without new line (#10858)
Browse files Browse the repository at this point in the history
  • Loading branch information
JaroslavTulach authored Aug 24, 2024
1 parent 7dc48b3 commit b6f0675
Show file tree
Hide file tree
Showing 12 changed files with 579 additions and 64 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,15 @@
- [Mixed Decimal/Float arithmetic now throws an error; mixed comparisons now
attach warnings.][10725]
- [Support for creating Atoms in expressions.][10820]
- [IO.print without new line][10858]

[10614]: https://github.com/enso-org/enso/pull/10614
[10660]: https://github.com/enso-org/enso/pull/10660
[10761]: https://github.com/enso-org/enso/pull/10761
[10733]: https://github.com/enso-org/enso/pull/10733
[10725]: https://github.com/enso-org/enso/pull/10725
[10820]: https://github.com/enso-org/enso/pull/10820
[10858]: https://github.com/enso-org/enso/pull/10858

#### Enso Language & Runtime

Expand Down
19 changes: 18 additions & 1 deletion distribution/lib/Standard/Base/0.0.0-dev/src/IO.enso
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import project.Any.Any
import project.Data.Text.Text
import project.Nothing.Nothing
import project.Internal.IO_Helpers

## PRIVATE
ADVANCED
Expand Down Expand Up @@ -30,7 +31,23 @@ print_err message = @Builtin_Method "IO.print_err"

IO.println "Oh yes!"
println : Any -> Nothing
println message = @Builtin_Method "IO.println"
println message = IO_Helpers.println message '\n'

## PRIVATE
ADVANCED
Prints the provided message to standard output without adding a new line at the end.

Arguments:
- message: The message to print. It will have to_text called on it to
generate a textual representation that is then printed.

> Example
Print the message "Oh yes!" to standard output using `print` and then `println`.

IO.print "Oh "
IO.println "yes!"
print : Any -> Nothing
print message = IO_Helpers.println message ''

## PRIVATE
ADVANCED
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@ private
# building native image version of Enso with Standard
# libraries included in

# needed for Standard.Test.Test_Reporter
# tracked as https://github.com/enso-org/enso/issues/10028
polyglot java import java.io.PrintStream

# needed by Util_Spec
polyglot java import org.enso.base.text.CaseFoldedString as JCaseFoldedString
polyglot java import org.enso.base.text.CaseFoldedString.Grapheme
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
private

println message ends_with = @Builtin_Method "IO.println"
16 changes: 8 additions & 8 deletions distribution/lib/Standard/Test/0.0.0-dev/src/Test_Reporter.enso
Original file line number Diff line number Diff line change
Expand Up @@ -194,17 +194,17 @@ print_progress current_progress total_count status_text =
truncated_line = if line.length <= progress_width then line else
line.take (progress_width - 3) + '...'

Java_System.out.print '\r'
Java_System.out.print (' ' * progress_width)
Java_System.out.print '\r'
Java_System.out.print truncated_line
Java_System.out.print '\r'
IO.print '\r'
IO.print (' ' * progress_width)
IO.print '\r'
IO.print truncated_line
IO.print '\r'

## PRIVATE
clear_progress =
Java_System.out.print '\r'
Java_System.out.print (' ' * progress_width)
Java_System.out.print '\r'
IO.print '\r'
IO.print (' ' * progress_width)
IO.print '\r'

## PRIVATE
type Ignore_Progress_Reporter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

import com.oracle.truffle.api.nodes.Node;
import java.io.File;
Expand Down Expand Up @@ -279,7 +280,7 @@ private static String extractPositions(
Assert.assertEquals(List.newBuilder().addOne(originalOutput), context.consumeOut());

var allNodesAfterException =
nodeCountingInstrument.assertNewNodes("Execution creates some nodes", 20, 35);
nodeCountingInstrument.assertNewNodes("Execution creates some nodes", 30, 40);

// push foo call
context.send(
Expand Down Expand Up @@ -354,7 +355,14 @@ private <T extends Node> T findLiteralNode(
Class<T> type, Map<Class, java.util.List<Node>> nodes) {
var intNodes = nodes.get(type);
assertNotNull("Found LiteralNode in " + nodes, intNodes);
assertEquals("Expecting one node: " + intNodes, 1, intNodes.size());
assertEquals("Expecting two nodes: " + intNodes, 2, intNodes.size());
if (intNodes.get(1) instanceof LiteralNode ln) {
var text = ln.executeGeneric(null);
assertEquals("The second node is ends_with from IO.println", "\n", text.toString());
} else {
fail("Expecting literal two nodes: " + intNodes);
}

return type.cast(intNodes.get(0));
}

Expand Down
Loading

0 comments on commit b6f0675

Please sign in to comment.