<commit_before>defmodule FarmbotCeleryScript.CompilerGroupsTest do
  use ExUnit.Case, async: true
  alias FarmbotCeleryScript.AST
  alias Farmbot.TestSupport.CeleryScript.TestSysCalls
  # alias FarmbotCeleryScript.Compiler
  # # Only required to compile
  # alias FarmbotCeleryScript.SysCalls, warn: false
  # alias FarmbotCeleryScript.Compiler.IdentifierSanitizer

  setup do
    {:ok, shim} = TestSysCalls.checkout()

    [shim: shim]
  end

  test "compilation of point_group in parameter application", %{shim: shim} do
    main = %AST{
      args: %{
        locals: %AST{
          args: %{},
          body: [
            %AST{
              args: %{
                default_value: %AST{
                  args: %{pointer_id: 1670, pointer_type: "Plant"},
                  body: [],
                  comment: nil,
                  kind: :point,
                  meta: nil
                },
                label: "parent"
              },
              body: [],
              comment: nil,
              kind: :parameter_declaration,
              meta: nil
            },
            %AST{
              args: %{
                data_value: %AST{
                  args: %{point_group_id: 34},
                  body: [],
                  comment: nil,
                  kind: :point_group,
                  meta: nil
                },
                label: "parent"
              },
              body: [],
              comment: nil,
              kind: :parameter_application,
              meta: nil
            }
          ],
          comment: nil,
          kind: :scope_declaration,
          meta: nil
        },
        sequence_name: "Pogo",
        version: 20_180_209
      },
      body: [],
      comment: nil,
      kind: :sequence,
      meta: %{sequence_name: "Pogo"}
    }

    pid = self()

    :ok =
      TestSysCalls.handle(shim, fn kind, args ->
        case kind do
          :get_point_group ->
            send(pid, {kind, args})
            %{name: "woosh", point_ids: [4, 5, 6]}

          :step_complete ->
            send(pid, {kind, args})
            {:NOOO}

          :point ->
            IO.puts("============== NoOoOoOooooo: " <> inspect(kind))
            %{hmm: args}
        end
      end)

    result = FarmbotCeleryScript.Compiler.Sequence.sequence(main, [])
    IO.inspect(result)
    IO.puts("Now what!?")
    assert result
  end
end<commit_msg>(50.8%, STABLE). Needs better assertions<commit_after>defmodule FarmbotCeleryScript.CompilerGroupsTest do
  use ExUnit.Case, async: true
  alias FarmbotCeleryScript.AST
  alias Farmbot.TestSupport.CeleryScript.TestSysCalls
  # alias FarmbotCeleryScript.Compiler
  # # Only required to compile
  # alias FarmbotCeleryScript.SysCalls, warn: false
  # alias FarmbotCeleryScript.Compiler.IdentifierSanitizer

  setup do
    {:ok, shim} = TestSysCalls.checkout()

    [shim: shim]
  end

  test "compilation of point_group in parameter application", %{shim: shim} do
    main = %AST{
      args: %{
        locals: %AST{
          args: %{},
          body: [
            %AST{
              args: %{
                default_value: %AST{
                  args: %{pointer_id: 1670, pointer_type: "Plant"},
                  body: [],
                  comment: nil,
                  kind: :point,
                  meta: nil
                },
                label: "parent"
              },
              body: [],
              comment: nil,
              kind: :parameter_declaration,
              meta: nil
            },
            %AST{
              args: %{
                data_value: %AST{
                  args: %{point_group_id: 34},
                  body: [],
                  comment: nil,
                  kind: :point_group,
                  meta: nil
                },
                label: "parent"
              },
              body: [],
              comment: nil,
              kind: :parameter_application,
              meta: nil
            }
          ],
          comment: nil,
          kind: :scope_declaration,
          meta: nil
        },
        sequence_name: "Pogo",
        version: 20_180_209
      },
      body: [],
      comment: nil,
      kind: :sequence,
      meta: %{sequence_name: "Pogo"}
    }

    pid = self()
    fake_point_ids = [4, 5, 6, 7]

    :ok =
      TestSysCalls.handle(shim, fn kind, args ->
        case kind do
          :get_point_group ->
            send(pid, {kind, args})
            %{name: "woosh", point_ids: fake_point_ids}

          :step_complete ->
            send(pid, {kind, args})
            {:NOOO}

          :point ->
            %{name: "from the test suite %%", x: 6, y: 7, z: 8}
        end
      end)

    result = FarmbotCeleryScript.Compiler.Sequence.sequence(main, [])
    assert length(result) === 2 + length(fake_point_ids)
  end
end
{'fraction_non_alphanumeric': 0.11154720099153068, 'fraction_numerical': 0.008675893410452386, 'mean_word_length': 1.3436592449177154, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5014048', 'n_tokens_mistral': 1487, 'n_tokens_neox': 1377, 'n_words': 323}