use v6.d;

use lib '.';
use lib './lib';

use Data::Translators;
use JSON::Fast;
use Test;

my $target = 'WL';

#===========================================================
## 1
#===========================================================
my $json1 = q:to/END/;
{
	"name": "Json2Html",
	"desription": "converts json 2 html table format"
}
END

my $res1 = q:to/END/;
Association["name"->"Json2Html", "desription"->"converts json 2 html table format"]
END

is
        data-translation($json1, :$target, field-names => <name desription>).subst(/\s/, ''):g,
        $res1.subst(/\s/, ''):g,
        'basic';

is
        data-translation(from-json($json1), :$target,  field-names => <name desription>),
        data-translation($json1, :$target,  field-names => <name desription>),
        'basic eqv';

#===========================================================
## 2
#===========================================================
my $ds2 = (${:id("304"), :passengerAge("60"), :passengerClass("1st"), :passengerSex("male"), :passengerSurvival("died")},
           ${:id("594"), :passengerAge("30"), :passengerClass("2nd"), :passengerSex("female"), :passengerSurvival("survived")},
           ${:id("1163"), :passengerAge("-1"), :passengerClass("3rd"), :passengerSex("male"), :passengerSurvival("survived")},
           ${:id("1038"), :passengerAge("-1"), :passengerClass("3rd"), :passengerSex("female"), :passengerSurvival("survived")});

my $res2 = q:to/END/;
List[
<|"id" -> "304", "passengerClass" -> "1st", "passengerSex" -> "male", "passengerAge" -> "60", "passengerSurvival" -> "died"|>,
<|"id" -> "594", "passengerClass" -> "2nd", "passengerSex" -> "female", "passengerAge" -> "30", "passengerSurvival" -> "survived"|>,
<|"id" -> "1163", "passengerClass" -> "3rd", "passengerSex" -> "male", "passengerAge" -> "-1", "passengerSurvival" -> "survived"|>,
<|"id" -> "1038", "passengerClass" -> "3rd", "passengerSex" -> "female", "passengerAge" -> "-1", "passengerSurvival" -> "survived"|>]
END

is
        data-translation($ds2, :$target, field-names => <id passengerClass passengerSex passengerAge passengerSurvival>).subst(/\s/,''):g,
        $res2.subst(/\s/,''):g,
        'dataset';

#===========================================================
## 3
#===========================================================
my $data3 = q:to/END/;
{
  "data": [
    {
      "id": 1,
      "name": "Alice",
      "age": 25,
      "profession": "Engineer"
    },
    {
      "id": 2,
      "name": "Bob",
      "age": 30,
      "profession": "Doctor"
    },
    {
      "id": 3,
      "name": "Charlie",
      "age": 28,
      "profession": "Artist"
    },
    {
      "id": 4,
      "name": "Diana",
      "age": 32,
      "profession": "Teacher"
    }
  ]
}
END

my $res3 = q:to/END/;
Association[
 "data" ->
  List[<|"name" -> "Alice", "id" -> 1, "age" -> 25,
    "profession" -> "Engineer"|>, <|"name" -> "Bob", "id" -> 2,
    "age" -> 30, "profession" -> "Doctor"|>, <|"name" -> "Charlie",
    "id" -> 3, "age" -> 28, "profession" -> "Artist"|>, <|
    "name" -> "Diana", "id" -> 4, "age" -> 32,
    "profession" -> "Teacher"|>]]
END

is
        data-translation($data3, :$target, field-names => <data name id age profession>).subst(/\s/,''):g,
        $res3.subst(/\s/,''):g,
        'professionals';

done-testing;
