Merge pull request #6 from moe-charm/copilot/fix-5
🏗️ Infrastructure-First Strategy: Unified Import System + Complete DateTimeBox + Comparison Operators
This commit is contained in:
@ -256,7 +256,7 @@ impl LiteralValue {
|
||||
/// LiteralValueをNyashBoxに変換
|
||||
pub fn to_nyash_box(&self) -> Box<dyn NyashBox> {
|
||||
use crate::box_trait::{StringBox, IntegerBox, BoolBox, VoidBox};
|
||||
use crate::boxes::math_box::FloatBox;
|
||||
use crate::boxes::FloatBox;
|
||||
|
||||
match self {
|
||||
LiteralValue::String(s) => Box::new(StringBox::new(s)),
|
||||
@ -272,7 +272,7 @@ impl LiteralValue {
|
||||
#[allow(unused_imports)]
|
||||
use std::any::Any;
|
||||
use crate::box_trait::{StringBox, IntegerBox, BoolBox, VoidBox};
|
||||
use crate::boxes::math_box::FloatBox;
|
||||
use crate::boxes::FloatBox;
|
||||
|
||||
if let Some(string_box) = box_val.as_any().downcast_ref::<StringBox>() {
|
||||
Some(LiteralValue::String(string_box.value.clone()))
|
||||
|
||||
@ -10,7 +10,7 @@
|
||||
*/
|
||||
|
||||
use crate::box_trait::{NyashBox, StringBox, IntegerBox, BoolBox};
|
||||
use crate::boxes::math_box::FloatBox;
|
||||
use crate::boxes::FloatBox;
|
||||
use crate::operator_traits::{
|
||||
NyashAdd, NyashSub, NyashMul, NyashDiv,
|
||||
DynamicAdd, DynamicSub, DynamicMul, DynamicDiv,
|
||||
|
||||
@ -1217,7 +1217,7 @@ pub struct CompareBox;
|
||||
|
||||
impl CompareBox {
|
||||
pub fn less(left: &dyn NyashBox, right: &dyn NyashBox) -> BoolBox {
|
||||
use crate::boxes::math_box::FloatBox;
|
||||
use crate::boxes::FloatBox;
|
||||
|
||||
// Integer < Integer
|
||||
if let (Some(left_int), Some(right_int)) = (
|
||||
@ -1255,7 +1255,7 @@ impl CompareBox {
|
||||
}
|
||||
|
||||
pub fn greater(left: &dyn NyashBox, right: &dyn NyashBox) -> BoolBox {
|
||||
use crate::boxes::math_box::FloatBox;
|
||||
use crate::boxes::FloatBox;
|
||||
|
||||
// Integer > Integer
|
||||
if let (Some(left_int), Some(right_int)) = (
|
||||
@ -1293,7 +1293,7 @@ impl CompareBox {
|
||||
}
|
||||
|
||||
pub fn less_equal(left: &dyn NyashBox, right: &dyn NyashBox) -> BoolBox {
|
||||
use crate::boxes::math_box::FloatBox;
|
||||
use crate::boxes::FloatBox;
|
||||
|
||||
// Integer <= Integer
|
||||
if let (Some(left_int), Some(right_int)) = (
|
||||
@ -1331,7 +1331,7 @@ impl CompareBox {
|
||||
}
|
||||
|
||||
pub fn greater_equal(left: &dyn NyashBox, right: &dyn NyashBox) -> BoolBox {
|
||||
use crate::boxes::math_box::FloatBox;
|
||||
use crate::boxes::FloatBox;
|
||||
|
||||
// Integer >= Integer
|
||||
if let (Some(left_int), Some(right_int)) = (
|
||||
|
||||
@ -104,7 +104,7 @@
|
||||
*/
|
||||
|
||||
use crate::box_trait::{BoxCore, BoxBase, NyashBox, StringBox, IntegerBox, BoolBox};
|
||||
use crate::boxes::array::ArrayBox;
|
||||
use crate::boxes::ArrayBox;
|
||||
use std::fmt::{Debug, Display};
|
||||
use std::any::Any;
|
||||
use std::collections::HashMap;
|
||||
|
||||
@ -77,7 +77,7 @@ pub use string_box::StringBox;
|
||||
pub use integer_box::IntegerBox;
|
||||
pub use bool_box::BoolBox;
|
||||
pub use math_box::{MathBox, FloatBox};
|
||||
pub use time_box::TimeBox;
|
||||
pub use time_box::{TimeBox, DateTimeBox};
|
||||
pub use debug_box::DebugBox;
|
||||
pub use random_box::RandomBox;
|
||||
pub use sound_box::SoundBox;
|
||||
|
||||
@ -34,9 +34,8 @@
|
||||
*/
|
||||
|
||||
use crate::box_trait::{NyashBox, StringBox, BoolBox, BoxCore, BoxBase};
|
||||
use crate::boxes::intent_box::IntentBox;
|
||||
use crate::boxes::{IntentBox, MapBox};
|
||||
pub use crate::boxes::intent_box::Message;
|
||||
use crate::boxes::map_box::MapBox;
|
||||
use std::any::Any;
|
||||
use std::sync::{Arc, Mutex};
|
||||
use std::collections::HashMap;
|
||||
|
||||
@ -68,8 +68,7 @@
|
||||
*/
|
||||
|
||||
use crate::box_trait::{NyashBox, StringBox, IntegerBox, BoolBox, BoxCore, BoxBase};
|
||||
use crate::boxes::array::ArrayBox;
|
||||
use crate::boxes::math_box::FloatBox;
|
||||
use crate::boxes::{ArrayBox, FloatBox};
|
||||
use std::fmt::{Debug, Display};
|
||||
use std::any::Any;
|
||||
use std::sync::{Arc, Mutex};
|
||||
|
||||
@ -47,7 +47,7 @@
|
||||
*/
|
||||
|
||||
use super::*;
|
||||
use crate::boxes::null_box::NullBox;
|
||||
use crate::boxes::NullBox;
|
||||
|
||||
impl NyashInterpreter {
|
||||
// StringBox methods moved to methods/basic_methods.rs
|
||||
|
||||
@ -9,8 +9,7 @@
|
||||
use super::*;
|
||||
use crate::ast::UnaryOperator;
|
||||
use crate::boxes::{buffer::BufferBox, JSONBox, HttpClientBox, StreamBox, RegexBox, IntentBox, P2PBox};
|
||||
use crate::boxes::math_box::FloatBox;
|
||||
use crate::boxes::{MathBox, ConsoleBox, TimeBox, RandomBox, SoundBox, DebugBox, file::FileBox, MapBox};
|
||||
use crate::boxes::{FloatBox, MathBox, ConsoleBox, TimeBox, DateTimeBox, RandomBox, SoundBox, DebugBox, file::FileBox, MapBox};
|
||||
use crate::box_trait::BoolBox;
|
||||
use crate::operator_traits::OperatorResolver;
|
||||
// TODO: Fix NullBox import issue later
|
||||
|
||||
@ -11,7 +11,7 @@
|
||||
|
||||
use super::super::*;
|
||||
use crate::box_trait::{StringBox, IntegerBox, BoolBox, VoidBox};
|
||||
use crate::boxes::math_box::FloatBox;
|
||||
use crate::boxes::FloatBox;
|
||||
|
||||
impl NyashInterpreter {
|
||||
/// StringBoxのメソッド呼び出しを実行
|
||||
|
||||
@ -9,8 +9,7 @@
|
||||
|
||||
use super::super::*;
|
||||
use crate::box_trait::{StringBox, IntegerBox, NyashBox, BoolBox};
|
||||
use crate::boxes::array::ArrayBox;
|
||||
use crate::boxes::map_box::MapBox;
|
||||
use crate::boxes::{ArrayBox, MapBox};
|
||||
|
||||
impl NyashInterpreter {
|
||||
/// ArrayBoxのメソッド呼び出しを実行
|
||||
|
||||
@ -9,7 +9,7 @@
|
||||
|
||||
use super::super::*;
|
||||
use crate::box_trait::{ResultBox, StringBox, NyashBox};
|
||||
use crate::boxes::file::FileBox;
|
||||
use crate::boxes::FileBox;
|
||||
|
||||
impl NyashInterpreter {
|
||||
/// FileBoxのメソッド呼び出しを実行
|
||||
|
||||
@ -7,9 +7,7 @@
|
||||
*/
|
||||
|
||||
use super::*;
|
||||
use crate::boxes::null_box::NullBox;
|
||||
use crate::boxes::console_box::ConsoleBox;
|
||||
use crate::boxes::math_box::FloatBox;
|
||||
use crate::boxes::{NullBox, ConsoleBox, FloatBox, DateTimeBox};
|
||||
// use crate::boxes::intent_box_wrapper::IntentBoxWrapper;
|
||||
use std::sync::Arc;
|
||||
|
||||
|
||||
@ -13,7 +13,7 @@
|
||||
*/
|
||||
|
||||
use super::*;
|
||||
use crate::boxes::sound_box::SoundBox;
|
||||
use crate::boxes::SoundBox;
|
||||
use crate::method_box::MethodBox;
|
||||
|
||||
impl NyashInterpreter {
|
||||
|
||||
@ -11,6 +11,7 @@
|
||||
|
||||
use super::*;
|
||||
use crate::box_trait::StringBox;
|
||||
use crate::boxes::{TimeBox, DateTimeBox};
|
||||
|
||||
impl NyashInterpreter {
|
||||
/// TimeBoxのメソッド呼び出しを実行
|
||||
@ -171,6 +172,14 @@ impl NyashInterpreter {
|
||||
}
|
||||
Ok(datetime_box.addHours(arg_values[0].clone_box()))
|
||||
}
|
||||
"toString" => {
|
||||
if !arg_values.is_empty() {
|
||||
return Err(RuntimeError::InvalidOperation {
|
||||
message: format!("toString() expects 0 arguments, got {}", arg_values.len()),
|
||||
});
|
||||
}
|
||||
Ok(Box::new(datetime_box.to_string_box()))
|
||||
}
|
||||
_ => {
|
||||
Err(RuntimeError::InvalidOperation {
|
||||
message: format!("Unknown DateTimeBox method: {}", method),
|
||||
|
||||
77
test_comparison_operators.nyash
Normal file
77
test_comparison_operators.nyash
Normal file
@ -0,0 +1,77 @@
|
||||
// test_comparison_operators.nyash - Comparison operators test
|
||||
// Phase 4: Comparison operators implementation validation
|
||||
|
||||
print("⚖️ Testing comparison operators implementation...")
|
||||
|
||||
// Basic variables for testing
|
||||
local f1, f2, i1, i2, s1, s2, result
|
||||
|
||||
// Test FloatBox comparisons
|
||||
f1 = new FloatBox(3.14)
|
||||
f2 = new FloatBox(2.86)
|
||||
|
||||
print("=== FloatBox Comparisons ===")
|
||||
result = f1 > f2
|
||||
print("3.14 > 2.86: " + result.toString())
|
||||
|
||||
result = f1 < f2
|
||||
print("3.14 < 2.86: " + result.toString())
|
||||
|
||||
result = f1 >= f2
|
||||
print("3.14 >= 2.86: " + result.toString())
|
||||
|
||||
result = f1 <= f2
|
||||
print("3.14 <= 2.86: " + result.toString())
|
||||
|
||||
result = f1 == f2
|
||||
print("3.14 == 2.86: " + result.toString())
|
||||
|
||||
result = f1 != f2
|
||||
print("3.14 != 2.86: " + result.toString())
|
||||
|
||||
// Test IntegerBox comparisons
|
||||
i1 = 10
|
||||
i2 = 5
|
||||
|
||||
print("=== IntegerBox Comparisons ===")
|
||||
result = i1 > i2
|
||||
print("10 > 5: " + result.toString())
|
||||
|
||||
result = i1 < i2
|
||||
print("10 < 5: " + result.toString())
|
||||
|
||||
result = i1 >= i2
|
||||
print("10 >= 5: " + result.toString())
|
||||
|
||||
result = i1 <= i2
|
||||
print("10 <= 5: " + result.toString())
|
||||
|
||||
result = i1 == i2
|
||||
print("10 == 5: " + result.toString())
|
||||
|
||||
result = i1 != i2
|
||||
print("10 != 5: " + result.toString())
|
||||
|
||||
// Test mixed type comparisons (FloatBox vs IntegerBox)
|
||||
print("=== Mixed Type Comparisons ===")
|
||||
result = f1 > i2
|
||||
print("3.14 > 5: " + result.toString())
|
||||
|
||||
result = f1 < i1
|
||||
print("3.14 < 10: " + result.toString())
|
||||
|
||||
result = i1 >= f1
|
||||
print("10 >= 3.14: " + result.toString())
|
||||
|
||||
result = i2 <= f2
|
||||
print("5 <= 2.86: " + result.toString())
|
||||
|
||||
// Test logical operators
|
||||
print("=== Logical Operators ===")
|
||||
result = (f1 > f2) and (i1 > i2)
|
||||
print("(3.14 > 2.86) and (10 > 5): " + result.toString())
|
||||
|
||||
result = (f1 < f2) or (i1 > i2)
|
||||
print("(3.14 < 2.86) or (10 > 5): " + result.toString())
|
||||
|
||||
print("✅ Comparison operators Phase 4 tests completed!")
|
||||
43
test_datetime_box.nyash
Normal file
43
test_datetime_box.nyash
Normal file
@ -0,0 +1,43 @@
|
||||
// test_datetime_box.nyash - DateTimeBox functionality test
|
||||
// Phase 3: DateTimeBox implementation validation
|
||||
|
||||
print("📅 Testing DateTimeBox implementation...")
|
||||
|
||||
// Basic DateTimeBox creation
|
||||
local now, timestamp_dt, parsed_dt, result
|
||||
|
||||
// Test 1: Current time creation
|
||||
now = new DateTimeBox()
|
||||
print("Current time: " + now.toString())
|
||||
|
||||
// Test 2: Timestamp creation
|
||||
timestamp_dt = new DateTimeBox(1640995200) // 2022-01-01 00:00:00 UTC
|
||||
print("From timestamp: " + timestamp_dt.toString())
|
||||
|
||||
// Test 3: Date component extraction
|
||||
result = now.year()
|
||||
print("Current year: " + result.toString())
|
||||
|
||||
result = now.month()
|
||||
print("Current month: " + result.toString())
|
||||
|
||||
result = now.day()
|
||||
print("Current day: " + result.toString())
|
||||
|
||||
result = now.hour()
|
||||
print("Current hour: " + result.toString())
|
||||
|
||||
result = now.minute()
|
||||
print("Current minute: " + result.toString())
|
||||
|
||||
result = now.second()
|
||||
print("Current second: " + result.toString())
|
||||
|
||||
// Test 4: Date arithmetic
|
||||
result = now.addDays(7)
|
||||
print("7 days from now: " + result.toString())
|
||||
|
||||
result = now.addHours(24)
|
||||
print("24 hours from now: " + result.toString())
|
||||
|
||||
print("✅ DateTimeBox Phase 3 tests completed!")
|
||||
Reference in New Issue
Block a user