# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.

cases:
  - note: data
    rego: |
      package test
      import data
      import input
    num_expressions: 3
    num_statements: 0
    num_queries: 0
    imports:
      - span: import data
        refr:
          var: data
          eidx: 1
      - span: import input
        refr:
          var: input
          eidx: 2

  - note: input
    rego: |
      package test
      import input
    num_expressions: 2
    num_statements: 0
    num_queries: 0
    imports:
      - span: import input
        refr:
          var: input
          eidx: 1

  - note: dot
    rego: |
      package test
      import input.a
      import data.b
    num_expressions: 5
    num_statements: 0
    num_queries: 0
    imports:
      - span: import input.a
        refr:
          refdot:
            refr:
              var: input
              eidx: 1
            field: a
          eidx: 2
      - span: import data.b
        refr:
          refdot:
            refr:
              var: data
              eidx: 3
            field: b
          eidx: 4

  - note: bracket
    rego: |
      package test
      import input["a"]
      import data["b"]
    num_expressions: 7
    num_statements: 0
    num_queries: 0
    imports:
      - span: import input["a"]
        refr:
          refbrack:
            refr:
              var: input
              eidx: 1
            index:
              string: a
              eidx: 2
          eidx: 3
      - span: import data["b"]
        refr:
          refbrack:
            refr:
              var: data
              eidx: 4
            index:
              string: b
              eidx: 5
          eidx: 6

  - note: multi-dot
    rego: |
      package test
      import input.a.b
      import data.c.d
    num_expressions: 7
    num_statements: 0
    num_queries: 0
    imports:
      - span: import input.a.b
        refr:
          refdot:
            span: input.a.b
            refr:
              refdot:
                span: input.a
                refr:
                  var: input
                  eidx: 1
                field: a
              eidx: 2
            field: b
          eidx: 3
      - span: import data.c.d
        refr:
          refdot:
            span: data.c.d
            refr:
              refdot:
                span: data.c
                refr:
                  var: data
                  eidx: 4
                field: c
              eidx: 5
            field: d
          eidx: 6
    policy: []


  - note: complex
    rego: |
      package test
      import    input["b.c"].d["e.f"].g
      import      data.a["b.c"].d["e.f"]
    num_expressions: 15
    num_statements: 0
    num_queries: 0
    package: --skip--
    imports:
      - span: import    input["b.c"].d["e.f"].g
        refr:
          refdot:
            span: input["b.c"].d["e.f"].g
            refr:
              refbrack:
                span: input["b.c"].d["e.f"]
                refr:
                  refdot:
                    span: input["b.c"].d
                    refr:
                      refbrack:
                        span: input["b.c"]
                        refr:
                          var: input
                          eidx: 1
                        index:
                          string: b.c
                          eidx: 2
                      eidx: 3
                    field: d
                  eidx: 4
                index:
                  string: e.f
                  eidx: 5
              eidx: 6
            field: g
          eidx: 7
      - span: import      data.a["b.c"].d["e.f"]
        refr:
          refbrack:
            span: data.a["b.c"].d["e.f"]
            refr:
              refdot:
                span: data.a["b.c"].d
                refr:
                  refbrack:
                    span: data.a["b.c"]
                    refr:
                      refdot:
                        span: data.a
                        refr:
                          var: data
                          eidx: 8
                        field: a
                      eidx: 9
                    index:
                      string: b.c
                      eidx: 10
                  eidx: 11
                field: d
              eidx: 12
            index:
              string: e.f
              eidx: 13
          eidx: 14

  - note:  same-line
    rego: package test import input.a["b"] import data["c"].d
    package:
      span: package test
      refr:
        var: test
        eidx: 0
    num_expressions: 9
    num_statements: 0
    num_queries: 0
    imports:
      - span: import input.a["b"]
        refr:
          refbrack:
            span: input.a["b"]
            refr:
              refdot:
                span: input.a
                refr:
                  var: input
                  eidx: 1
                field: a
              eidx: 2
            index:
              string: b
              eidx: 3
          eidx: 4
      - span: import data["c"].d
        refr:
          refdot:
            span: data["c"].d
            refr:
              refbrack:
                span: data["c"]
                refr:
                  var: data
                  eidx: 5
                index:
                  string: c
                  eidx: 6
              eidx: 7
            field: d
          eidx: 8
  - note: as
    rego: |
      package test
      import input.x as y
    num_expressions: 3
    num_statements: 0
    num_queries: 0
    imports:
      - span: import input.x as y
        refr:
          refdot:
            span: input.x
            refr:
              var: input
              eidx: 1
            field: x
          eidx: 2
        as: y

  - note: as/newline
    rego: |
      package test
      import
      input.x
      as
      y
    num_expressions: 3
    num_statements: 0
    num_queries: 0
    imports:
      - span: "import\ninput.x\nas\ny"
        refr:
          refdot:
            span: input.x
            refr:
              var: input
              eidx: 1
            field: x
          eidx: 2
        as: y

  - note: missing-ref
    rego: |
      package test
      import ( a)
    error: expecting identifier

  - note: missing-ref-1
    rego: |
      package test
      import ["a"]
    error: expecting identifier

  - note: invalid-beginning
    rego: |
      package test
      import foo
    error: "import path must begin with one of: {data, future, input, rego}"

  - note: invalid-beginning-1
    rego: |
      package test
      import foo.bar
    error: "import path must begin with one of: {data, future, input, rego}"

  - note: missing-field-1
    rego: |
      package test
      import data.a.
    error: expecting identifier

  - note: missing-field-2
    rego: |
      package test
      import data.a.b.
    error: expecting identifier

  - note: space-after-dot
    rego: |
      package test
      import input. a
    error: invalid whitespace between . and identifier

  - note: space-before-dot
    rego: |
      package test
      import input .a.b
    error: invalid whitespace before .

  - note: space-after-lbracket
    rego: package test import a ["b"]
    error: invalid whitespace before [

  - note: non-string-index
    rego: package test import a[1]
    error: expected string

  - note: shadow
    rego:
      package test
      import data.x import data.y import data["x"]
    error: import shadows following import defined earlier

  - note: keyword/else
    rego:
      package test
      import data.x as else
    error: "unexpected keyword `else`"

  - note: keyword/as
    rego:
      package test
      import data.x as as
    error: "unexpected keyword `as`"

  - note: as/_
    rego:
      package test
      import data.x as _
    error: "`_` cannot be used as alias"

  - note: as/_
    rego:
      package test
      import data.x as 1
    error: expecting identifier

  - note: as/eof
    rego:
      package test
      import data.x as
    error: expecting identifier

  - note: as/multiple
    rego:
      package test
      import data.x as y
      import data.y as y
    error: import shadows following import defined earlier
