diff --git a/eo-runtime/src/main/java/org/eolang/PhLocated.java b/eo-runtime/src/main/java/org/eolang/PhLocated.java index 8255015cf0..eda2b74b93 100644 --- a/eo-runtime/src/main/java/org/eolang/PhLocated.java +++ b/eo-runtime/src/main/java/org/eolang/PhLocated.java @@ -105,7 +105,7 @@ public String toString() { @Override public Phi copy() { - return new PhLocated(this.origin.copy(), this.line, this.position); + return new PhLocated(this.origin.copy(), this.line, this.position, this.location); } @Override diff --git a/eo-runtime/src/test/eo/org/eolang/rust-tests.eo b/eo-runtime/src/test/eo/org/eolang/rust-tests.eo index 46fd65e0a6..f210467c07 100644 --- a/eo-runtime/src/test/eo/org/eolang/rust-tests.eo +++ b/eo-runtime/src/test/eo/org/eolang/rust-tests.eo @@ -25,372 +25,369 @@ +package org.eolang +version 0.0.0 +# Test +[] > rust-returns-positive-int + QQ.rust > r + """ + use eo::Portal; + use eo::eo_enum::EO; + use eo::eo_enum::EO::{EOInt}; + + pub fn foo(_portal: &mut Portal) -> Option { + println!("Hello world from rust"); + Some(EOInt(2)) + } + """ + [] + * + eq. > @ + r + 2 + # Test. -# @todo #2931:30min Enable rust tests. The tests were disabled because they stopped work after -# changing attributes dispatch logic. Now every time we "take" attribute - it's copied. So rust -# is not working because of it anymore. Need to find out what's going on and enable the tests. -[] > rust-tests - TRUE > @ - # Test. - [] > rust-returns-positive-int - QQ.rust > r - """ - use eo::Portal; - use eo::eo_enum::EO; - use eo::eo_enum::EO::{EOInt}; - - pub fn foo(_portal: &mut Portal) -> Option { - println!("Hello world from rust"); - Some(EOInt(2)) - } - """ - [] - * - eq. > @ - r - 2 - - # Test. - [] > rust-returns-negative-int - QQ.rust > r - """ - use eo::Portal; - use eo::eo_enum::EO; - use eo::eo_enum::EO::{EOInt}; - - pub fn foo(_portal: &mut Portal) -> Option { - println!("Hello world from rust"); - Some(EOInt(-10)) - } - """ - [] - * - eq. > @ - r - -10 - - # Test. - [] > rust-returns-positive-double - QQ.rust > r - """ - use eo::Portal; - use eo::eo_enum::EO; - use eo::eo_enum::EO::{EOFloat}; - - pub fn foo(_portal: &mut Portal) -> Option { - Some(EOFloat(1.23456789)) - } - """ - [] - * - eq. > @ - r - 1.23456789 - - # Test. - [] > rust-returns-negative-double - QQ.rust > r - """ - use eo::Portal; - use eo::eo_enum::EO; - use eo::eo_enum::EO::{EOFloat}; - - pub fn foo(_portal: &mut Portal) -> Option { - Some(EOFloat(-1.23456789)) - } - """ - [] - * - eq. > @ - r - -1.23456789 - - # Test. - [] > rust-is-byte-array - QQ.rust > my-bytes - """ - use eo::Portal; - use eo::eo_enum::EO; - use eo::eo_enum::EO::{EORaw}; - - pub fn foo(_portal: &mut Portal) -> Option { - Some( - EORaw( - Box::from( - [0x00, 0x1a, 0xEE] - ) +[] > rust-returns-negative-int + QQ.rust > r + """ + use eo::Portal; + use eo::eo_enum::EO; + use eo::eo_enum::EO::{EOInt}; + + pub fn foo(_portal: &mut Portal) -> Option { + println!("Hello world from rust"); + Some(EOInt(-10)) + } + """ + [] + * + eq. > @ + r + -10 + +# Test. +[] > rust-returns-positive-double + QQ.rust > r + """ + use eo::Portal; + use eo::eo_enum::EO; + use eo::eo_enum::EO::{EOFloat}; + + pub fn foo(_portal: &mut Portal) -> Option { + Some(EOFloat(1.23456789)) + } + """ + [] + * + eq. > @ + r + 1.23456789 + +# Test. +[] > rust-returns-negative-double + QQ.rust > r + """ + use eo::Portal; + use eo::eo_enum::EO; + use eo::eo_enum::EO::{EOFloat}; + + pub fn foo(_portal: &mut Portal) -> Option { + Some(EOFloat(-1.23456789)) + } + """ + [] + * + eq. > @ + r + -1.23456789 + +# Test. +[] > rust-is-byte-array + QQ.rust > my-bytes + """ + use eo::Portal; + use eo::eo_enum::EO; + use eo::eo_enum::EO::{EORaw}; + + pub fn foo(_portal: &mut Portal) -> Option { + Some( + EORaw( + Box::from( + [0x00, 0x1a, 0xEE] ) ) - } - """ - [] - * - eq. > @ - my-bytes - 00-1A-EE - - # Test. - [] > rust-find-returns-int - 123 > a - QQ.rust > r - """ - use eo::Portal; - use eo::eo_enum::EO; - use eo::eo_enum::EO::{EOInt}; - - pub fn foo(portal: &mut Portal) -> Option { - Some( - EOInt(portal.find("$.&.a")? as i64) - ) - } - """ - [] - * - not. > @ - lt. - r - 0 - - # Test. - [] > rust-returns-vertex - "content" > book - QQ.rust > read - """ - use eo::Portal; - use eo::eo_enum::EO; - use eo::eo_enum::EO::{EOVertex}; - - pub fn foo(portal: &mut Portal) -> Option { - let v = portal.find("$.&.book")?; - Some(EOVertex(v)) - } - """ - [] - * - eq. > @ - read - "content" - - # Test. - [] > rust-is-string - QQ.rust > content - """ - use eo::Portal; - use eo::eo_enum::EO; - use eo::eo_enum::EO::{EOString}; - - pub fn foo(_portal: &mut Portal) -> Option { - Some(EOString("Привет world".to_string())) - } - """ - [] - * - eq. > @ - content - "Привет world" - - # Test. - [] > rust-invalid-put - QQ.rust > put - """ - use eo::Portal; - use eo::eo_enum::EO; - use eo::eo_enum::EO::{EOInt, EOError}; - - pub fn foo(portal: &mut Portal) -> Option { - portal.put(-1i32 as u32, &[0x00, 0x1a, 0xEE, 0xf, 0xf3])?; - Some(EOError("put failed".to_string())) - } - """ - [] - * - eq. > @ - slice. - try - [] - put > @ - [e] - e > @ - nop - 0 - 18 - "Rust insert failed" - - # Test. - [] > rust-bind-not-fails - 1 > a - 2 > b - "Rust insert failed" > to-check - QQ.rust > insert - """ - use eo::Portal; - use eo::eo_enum::EO; - use eo::eo_enum::EO::{EOInt}; - - pub fn foo(portal: &mut Portal) -> Option { - let v1 = portal.find("$.&.a")?; - let v2 = portal.find("$.&.b")?; - portal.bind(v1 , v2, "EO-att")?; - Some(EOInt(0 as i64)) - } - """ - [] - * - try > res - [] - insert > @ - [e] - e > @ - nop - eq. > @ - res.slice - 0 - to-check.length - to-check - - # Test. - [] > rust-copy-not-fails - 123 > a - QQ.rust > copy - """ - use eo::Portal; - use eo::eo_enum::EO; - use eo::eo_enum::EO::{EOVertex}; - pub fn foo(portal: &mut Portal) -> Option { - let v = portal.find("$.&.a")?; - let copy = portal.copy(v)?; - Some(EOVertex(copy)) - } - """ - [] - * - eq. > @ - copy - 123 - - # Test. - [] > rust-dataize-not-fails - 1 > a - QQ.rust > dataized - """ - use eo::Portal; - use eo::eo_enum::EO; - use eo::eo_enum::EO::{EOInt}; - - pub fn foo(portal: &mut Portal) -> Option { - let v = portal.find("$.&.a")?; - let _bytes = portal.dataize(v)?; - Some(EOInt(v as i64)) - } - """ - [] - * - not. > @ - lt. - dataized - 0 - - # Test. - [] > rust-plus - 5 > a - 10 > b - QQ.rust > plus - """ - use eo::Portal; - use eo::eo_enum::EO; - use eo::eo_enum::EO::{EOInt}; - use byteorder::{BigEndian, ReadBytesExt}; - - pub fn foo(portal: &mut Portal) -> Option { - let a = portal.find("$.&.a")?; - let bytes_a = portal.dataize(a)?; - let a = bytes_a.as_slice().read_i64::().ok()?; - - let b = portal.find("$.&.b")?; - let bytes_b = portal.dataize(b)?; - let b = bytes_b.as_slice().read_i64::().ok()?; - println!("sum 5 + 10 = {}", a + b); - - Some(EOInt(a + b)) - } - """ - [] - * - "byteorder:1.4.3" - eq. > @ - plus - 15 - - # Test. - [] > rust-error - "Rust insert failed " > message - QQ.rust > err - """ - use eo::Portal; - use eo::eo_enum::EO; - use eo::eo_enum::EO::{EOError}; - pub fn foo(_portal: &mut Portal) -> Option { - Some(EOError("Custom error".to_string())) - } - """ - [] - * - try > res - [] - err > @ - [e] - e > @ - nop - eq. > @ - slice. - res - 0 - length. - message - message - - # Test. - [] > rust-put-to-copy - QQ.rust > data - """ - use eo::Portal; - use eo::eo_enum::EO; - use eo::eo_enum::EO::{EOVertex, EOError}; - - pub fn foo(portal: &mut Portal) -> Option { - let eobytes = portal.find("Q.org.eolang.bytes")?; - let copy = portal.copy(eobytes)?; - portal.put(copy.clone(), &[0x00, 0x1a, 0xEE])?; - Some(EOVertex(copy)) - } - """ - [] - * - eq. > @ - data - 00-1A-EE - - # Test. - [] > rust-bind-to-copy - # Book. - [content] > book - "qwerty" > line - QQ.rust > applied - """ - use eo::Portal; - use eo::eo_enum::EO; - use eo::eo_enum::EO::{EOVertex}; - - pub fn foo(portal: &mut Portal) -> Option { - let eobook = portal.find("$.&.book")?; - let copy = portal.copy(eobook)?; - let eoline = portal.find("$.&.line")?; - portal.bind(copy.clone(), eoline, "content")?; - Some(EOVertex(copy)) - } - """ - [] - * - eq. > @ - applied.content - "qwerty" + ) + } + """ + [] + * + eq. > @ + my-bytes + 00-1A-EE + +# Test. +[] > rust-find-returns-int + 123 > a + QQ.rust > r + """ + use eo::Portal; + use eo::eo_enum::EO; + use eo::eo_enum::EO::{EOInt}; + + pub fn foo(portal: &mut Portal) -> Option { + Some( + EOInt(portal.find("$.&.a")? as i64) + ) + } + """ + [] + * + not. > @ + lt. + r + 0 + +# Test. +[] > rust-returns-vertex + "content" > book + QQ.rust > read + """ + use eo::Portal; + use eo::eo_enum::EO; + use eo::eo_enum::EO::{EOVertex}; + + pub fn foo(portal: &mut Portal) -> Option { + let v = portal.find("$.&.book")?; + Some(EOVertex(v)) + } + """ + [] + * + eq. > @ + read + "content" + +# Test. +[] > rust-is-string + QQ.rust > content + """ + use eo::Portal; + use eo::eo_enum::EO; + use eo::eo_enum::EO::{EOString}; + + pub fn foo(_portal: &mut Portal) -> Option { + Some(EOString("Привет world".to_string())) + } + """ + [] + * + eq. > @ + content + "Привет world" + +# Test. +[] > rust-invalid-put + "Error at \"EOorg.EOeolang.EOrust#λ\" attribute; caused by Rust insert failed " > message + QQ.rust > put + """ + use eo::Portal; + use eo::eo_enum::EO; + use eo::eo_enum::EO::{EOInt, EOError}; + + pub fn foo(portal: &mut Portal) -> Option { + portal.put(-1i32 as u32, &[0x00, 0x1a, 0xEE, 0xf, 0xf3])?; + Some(EOError("put failed".to_string())) + } + """ + [] + * + eq. > @ + slice. + try + [] + put > @ + [e] + e > @ + nop + 0 + length. + message + message + +# Test. +[] > rust-invalid-bind + 1 > a + 2 > b + "Error at \"EOorg.EOeolang.EOrust#λ\" attribute; caused by Rust insert failed " > to-check + QQ.rust > insert + """ + use eo::Portal; + use eo::eo_enum::EO; + use eo::eo_enum::EO::{EOInt}; + + pub fn foo(portal: &mut Portal) -> Option { + let v1 = portal.find("$.&.a")?; + let v2 = portal.find("$.&.b")?; + portal.bind(v1 , v2, "EO-att")?; + Some(EOInt(0 as i64)) + } + """ + [] + * + try > res + [] + insert > @ + [e] + e > @ + nop + eq. > @ + res.slice + 0 + to-check.length + to-check + +# Test. +[] > rust-copy-not-fails + 123 > a + QQ.rust > copy + """ + use eo::Portal; + use eo::eo_enum::EO; + use eo::eo_enum::EO::{EOVertex}; + + pub fn foo(portal: &mut Portal) -> Option { + let v = portal.find("$.&.a")?; + let copy = portal.copy(v)?; + Some(EOVertex(copy)) + } + """ + [] + * + eq. > @ + copy + 123 + +# Test. +[] > rust-dataize-not-fails + 1 > a + QQ.rust > dataized + """ + use eo::Portal; + use eo::eo_enum::EO; + use eo::eo_enum::EO::{EOInt}; + + pub fn foo(portal: &mut Portal) -> Option { + let v = portal.find("$.&.a")?; + let _bytes = portal.dataize(v)?; + Some(EOInt(v as i64)) + } + """ + [] + * + not. > @ + lt. + dataized + 0 + +# Test. +[] > rust-plus + 5 > a + 10 > b + QQ.rust > plus + """ + use eo::Portal; + use eo::eo_enum::EO; + use eo::eo_enum::EO::{EOInt}; + use byteorder::{BigEndian, ReadBytesExt}; + + pub fn foo(portal: &mut Portal) -> Option { + let a = portal.find("$.&.a")?; + let bytes_a = portal.dataize(a)?; + let a = bytes_a.as_slice().read_i64::().ok()?; + + let b = portal.find("$.&.b")?; + let bytes_b = portal.dataize(b)?; + let b = bytes_b.as_slice().read_i64::().ok()?; + println!("sum 5 + 10 = {}", a + b); + Some(EOInt(a + b)) + } + """ + [] + * + "byteorder:1.4.3" + eq. > @ + plus + 15 + +# Test. +[] > rust-error + "Error at \"EOorg.EOeolang.EOrust#λ\" attribute; caused by Rust insert failed " > message + QQ.rust > err + """ + use eo::Portal; + use eo::eo_enum::EO; + use eo::eo_enum::EO::{EOError}; + + pub fn foo(_portal: &mut Portal) -> Option { + Some(EOError("Custom error".to_string())) + } + """ + [] + * + try > res + [] + err > @ + [e] + e > @ + nop + eq. > @ + slice. + res + 0 + length. + message + message + +# Test. +[] > rust-put-to-copy + QQ.rust > data + """ + use eo::Portal; + use eo::eo_enum::EO; + use eo::eo_enum::EO::{EOVertex, EOError}; + + pub fn foo(portal: &mut Portal) -> Option { + let eobytes = portal.find("Q.org.eolang.bytes")?; + let copy = portal.copy(eobytes)?; + portal.put(copy.clone(), &[0x00, 0x1a, 0xEE])?; + Some(EOVertex(copy)) + } + """ + [] + * + eq. > @ + data + 00-1A-EE + +# Test. +[] > rust-bind-to-copy + # Book. + [content] > book + "qwerty" > line + QQ.rust > applied + """ + use eo::Portal; + use eo::eo_enum::EO; + use eo::eo_enum::EO::{EOVertex}; + + pub fn foo(portal: &mut Portal) -> Option { + let eobook = portal.find("$.&.book")?; + let copy = portal.copy(eobook)?; + let eoline = portal.find("$.&.line")?; + portal.bind(copy.clone(), eoline, "content")?; + Some(EOVertex(copy)) + } + """ + [] + * + eq. > @ + applied.content + "qwerty" diff --git a/eo-runtime/src/test/java/org/eolang/PhLocatedTest.java b/eo-runtime/src/test/java/org/eolang/PhLocatedTest.java new file mode 100644 index 0000000000..71b02d6d68 --- /dev/null +++ b/eo-runtime/src/test/java/org/eolang/PhLocatedTest.java @@ -0,0 +1,45 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2016-2024 Objectionary.com + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package org.eolang; + +import org.hamcrest.MatcherAssert; +import org.hamcrest.Matchers; +import org.junit.jupiter.api.Test; + +/** + * Test case for {@link PhLocatedTest}. + * + * @since 0.36.0 + */ +class PhLocatedTest { + + @Test + void savesLocationAfterCopying() { + final Phi located = new PhLocated(new Data.ToPhi(0L), 123, 124, "qwerty"); + MatcherAssert.assertThat( + located.copy().locator(), + Matchers.equalTo(located.locator()) + ); + } +}