// Copyright 2025 International Digital Economy Academy
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
///|
pub(all) enum Weekday {
Monday
Tuesday
Wednesday
Thursday
Friday
Saturday
Sunday
} derive(Eq, Debug)
///|
pub impl Show for Weekday with fn output(self : Weekday, logger : &Logger) -> Unit {
match self {
Monday => logger.write_string("Monday")
Tuesday => logger.write_string("Tuesday")
Wednesday => logger.write_string("Wednesday")
Thursday => logger.write_string("Thursday")
Friday => logger.write_string("Friday")
Saturday => logger.write_string("Saturday")
Sunday => logger.write_string("Sunday")
}
}
///|
fn Weekday::new(week_day : Int) -> Weekday? {
match week_day {
1 => Some(Monday)
2 => Some(Tuesday)
3 => Some(Wednesday)
4 => Some(Thursday)
5 => Some(Friday)
6 => Some(Saturday)
7 => Some(Sunday)
_ => None
}
}
///|
fn Weekday::value(self : Weekday) -> Int {
match self {
Monday => 1
Tuesday => 2
Wednesday => 3
Thursday => 4
Friday => 5
Saturday => 6
Sunday => 7
}
}
///|
test "new" {
debug_inspect(Weekday::new(0), content="None")
debug_inspect(Weekday::new(1), content="Some(Monday)")
debug_inspect(Weekday::new(2), content="Some(Tuesday)")
debug_inspect(Weekday::new(3), content="Some(Wednesday)")
debug_inspect(Weekday::new(4), content="Some(Thursday)")
debug_inspect(Weekday::new(5), content="Some(Friday)")
debug_inspect(Weekday::new(6), content="Some(Saturday)")
debug_inspect(Weekday::new(7), content="Some(Sunday)")
debug_inspect(Weekday::new(8), content="None")
}
///|
test "value" {
inspect(Weekday::Monday.value(), content="1")
inspect(Weekday::Tuesday.value(), content="2")
inspect(Weekday::Wednesday.value(), content="3")
inspect(Weekday::Thursday.value(), content="4")
inspect(Weekday::Friday.value(), content="5")
inspect(Weekday::Saturday.value(), content="6")
inspect(Weekday::Sunday.value(), content="7")
}
///|
test "show" {
inspect(
Monday,
content=(
#|Monday
),
)
inspect(
Sunday,
content=(
#|Sunday
),
)
}