<commit_before>{-# LANGUAGE TemplateHaskell #-}
{-# Language QuasiQuotes #-}
{-# LANGUAGE OverloadedStrings #-}

module Unison.Test.Codebase.Upgrade12 (test) where

import Data.Functor (void)
import Data.String.Here.Interpolated (i)
import EasyTest (Test, io, ok, scope, tests)
import Shellmet ()
import qualified Unison.Test.Ucm as Ucm

test :: Test ()
test = scope "codebase.upgrade12" $
  tests [typeAlias, topLevelTerm, subNamespace, accessPatch, accessHistory]

typeAlias :: Test ()
typeAlias = scope "typeAlias" do
  void $ io do
    c1 <- Ucm.initCodebase Ucm.CodebaseFormat1
    Ucm.runTranscript c1 Ucm.Runtime1 [i|
        ```ucm
        .> alias.type ##Nat builtin.Nat
        .> history
        .> history builtin
        ```
      |]
    c2 <- Ucm.upgradeCodebase c1
    Ucm.runTranscript c2 Ucm.Runtime1 [i|
        ```unison
        x : Nat
        x = 3
        ```
      |]
  ok

topLevelTerm :: Test ()
topLevelTerm = scope "topLevelTerm" $ do
  void $ io do
    c1 <- Ucm.initCodebase Ucm.CodebaseFormat1
    Ucm.runTranscript c1 Ucm.Runtime1 [i|
        ```unison:hide
        y = 3
        ```
        ```ucm
        .> add
        ```
      |]
    c2 <- Ucm.upgradeCodebase c1
    Ucm.runTranscript c2 Ucm.Runtime1 [i|
      ```ucm
      .> find
      ```
      ```unison
      > y
      ```
    |]
  ok

subNamespace :: Test ()
subNamespace = scope "subNamespace" do
  void $ io do
    c1 <- Ucm.initCodebase Ucm.CodebaseFormat1
    Ucm.runTranscript c1 Ucm.Runtime1 [i|
        ```ucm
        .> alias.type ##Nat builtin.Nat
        ```
        ```unison
        unique type a.b.C = C Nat
        ```
        ```ucm
        .> add
        ```
      |]
    c2 <- Ucm.upgradeCodebase c1
    Ucm.runTranscript c2 Ucm.Runtime1 [i|
      ```ucm
      .> find
      ```
      ```unison
      > a.b.C.C 3
      ```
    |]
  ok

accessPatch :: Test ()
accessPatch = scope "accessPatch" do
  void $ io do
    c1 <- Ucm.initCodebase Ucm.CodebaseFormat1
    Ucm.runTranscript c1 Ucm.Runtime1 [i|
        ```ucm
        .> alias.type ##Nat builtin.Nat
        ```
        ```unison:hide
        unique type A = A Nat
        foo = A.A 3
        ```
        ```ucm
        .> debug.file
        .> add
        ```
        ```unison:hide
        unique type A = A Nat Nat
        foo = A.A 3 3
        ```
        ```ucm
        .> debug.file
        .> update
        ```
        ```ucm
        .> view.patch patch
        ```
      |]
    c2 <- Ucm.upgradeCodebase c1
    Ucm.runTranscript c2 Ucm.Runtime1 [i|
      ```ucm
      .> view.patch patch
      ```
    |]
  ok

-- #00k3c9bp6m A
-- #6v94dtbfk1 foo
-- #d3bn4dqp1a A'
-- #p3a21bjjl4 foo'

accessHistory :: Test ()
accessHistory = scope "history" do
  void $ io do
    c1 <- Ucm.initCodebase Ucm.CodebaseFormat1
    Ucm.runTranscript c1 Ucm.Runtime1 [i|
        ```unison
        foo = 3
        ```
        ```ucm
        .> add
        ```
        ```unison
        foo = 4
        ```
        ```ucm
        .> update
        .> history
        ```
      |]
    c2 <- Ucm.upgradeCodebase c1
    Ucm.runTranscript c2 Ucm.Runtime1 [i|
        ```ucm
        .> history
        .> reset-root #ls8
        .> history
        ```
      |]
  ok<commit_msg>reformat tests and add link test<commit_after>{-# LANGUAGE TemplateHaskell #-}
{-# Language QuasiQuotes #-}
{-# LANGUAGE OverloadedStrings #-}

module Unison.Test.Codebase.Upgrade12 (test) where

import Data.Functor (void)
import Data.String.Here.Interpolated (i)
import EasyTest (Test, io, ok, scope, tests)
import Shellmet ()
import qualified Unison.Test.Ucm as Ucm

test :: Test ()
test = scope "codebase.upgrade12" $ tests [
  scope "typeAlias" do
    void $ io do
      c1 <- Ucm.initCodebase Ucm.CodebaseFormat1
      Ucm.runTranscript c1 Ucm.Runtime1 [i|
          ```ucm
          .> alias.type ##Nat builtin.Nat
          .> history
          .> history builtin
          ```
        |]
      c2 <- Ucm.upgradeCodebase c1
      Ucm.runTranscript c2 Ucm.Runtime1 [i|
          ```unison
          x : Nat
          x = 3
          ```
        |]
    ok,

  scope "topLevelTerm" do
    void $ io do
      c1 <- Ucm.initCodebase Ucm.CodebaseFormat1
      Ucm.runTranscript c1 Ucm.Runtime1 [i|
          ```unison:hide
          y = 3
          ```
          ```ucm
          .> add
          ```
        |]
      c2 <- Ucm.upgradeCodebase c1
      Ucm.runTranscript c2 Ucm.Runtime1 [i|
        ```ucm
        .> find
        ```
        ```unison
        > y
        ```
      |]
    ok,

  scope "metadataForTerm" do
    void $ io do
      c1 <- Ucm.initCodebase Ucm.CodebaseFormat1
      Ucm.runTranscript c1 Ucm.Runtime1 ""
      Ucm.runTranscript c1 Ucm.Runtime1 [i|
          ```unison:hide
          doc = "y is the number 3"
          y = 3
          ```
          ```ucm
          .> add
          .> link doc y
          ```
        |]
      Ucm.runTranscript c1 Ucm.Runtime1 [i|
        ```ucm
        .> links y
        ```
      |]
      c2 <- Ucm.upgradeCodebase c1
      Ucm.runTranscript c2 Ucm.Runtime1 [i|
        ```ucm
        .> links y
        ```
      |]
    ok,

  scope "metadataForType" do
    void $ io do
      c1 <- Ucm.initCodebase Ucm.CodebaseFormat1
      Ucm.runTranscript c1 Ucm.Runtime1 [i|
          ```unison:hide
          doc = "Nat means natural number"
          ```
          ```ucm
          .> alias.type ##Nat Nat
          .> link doc Nat
          ```
        |]
      c2 <- Ucm.upgradeCodebase c1
      Ucm.runTranscript c2 Ucm.Runtime1 [i|
        ```ucm
        .> docs y
        ```
      |]
    ok,

  scope "subNamespace" do
    void $ io do
      c1 <- Ucm.initCodebase Ucm.CodebaseFormat1
      Ucm.runTranscript c1 Ucm.Runtime1 [i|
          ```ucm
          .> alias.type ##Nat builtin.Nat
          ```
          ```unison
          unique type a.b.C = C Nat
          ```
          ```ucm
          .> add
          ```
        |]
      c2 <- Ucm.upgradeCodebase c1
      Ucm.runTranscript c2 Ucm.Runtime1 [i|
        ```ucm
        .> find
        ```
        ```unison
        > a.b.C.C 3
        ```
      |]
    ok,

  scope "accessPatch" do
    void $ io do
      c1 <- Ucm.initCodebase Ucm.CodebaseFormat1
      Ucm.runTranscript c1 Ucm.Runtime1 [i|
          ```ucm
          .> alias.type ##Nat builtin.Nat
          ```
          ```unison:hide
          unique type A = A Nat
          foo = A.A 3
          ```
          ```ucm
          .> debug.file
          .> add
          ```
          ```unison:hide
          unique type A = A Nat Nat
          foo = A.A 3 3
          ```
          ```ucm
          .> debug.file
          .> update
          ```
          ```ucm
          .> view.patch patch
          ```
        |]
      c2 <- Ucm.upgradeCodebase c1
      Ucm.runTranscript c2 Ucm.Runtime1 [i|
        ```ucm
        .> view.patch patch
        ```
      |]
    ok,

-- #00k3c9bp6m A
-- #6v94dtbfk1 foo
-- #d3bn4dqp1a A'
-- #p3a21bjjl4 foo'

  scope "history" do
    void $ io do
      c1 <- Ucm.initCodebase Ucm.CodebaseFormat1
      Ucm.runTranscript c1 Ucm.Runtime1 [i|
          ```unison
          foo = 3
          ```
          ```ucm
          .> add
          ```
          ```unison
          foo = 4
          ```
          ```ucm
          .> update
          .> history
          ```
        |]
      c2 <- Ucm.upgradeCodebase c1
      Ucm.runTranscript c2 Ucm.Runtime1 [i|
          ```ucm
          .> history
          .> reset-root #ls8
          .> history
          ```
        |]
    ok
  ]
{'fraction_non_alphanumeric': 0.12709385801648498, 'fraction_numerical': 0.02127093858016485, 'mean_word_length': 1.3575681604512693, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 56, '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': '3832030', 'n_tokens_mistral': 2670, 'n_tokens_neox': 2580, 'n_words': 589}