Back
ends-with? (clj)
(source)function
(ends-with? s substr)
True if s ends with substr.
Examples
clojure
(ns clojure.test-clojure.string
(:require [clojure.string :as s])
(:use clojure.test))
(deftest t-ends-with?
(is (s/ends-with? (StringBuffer. "Clojure West") "West")
(is (not (s/ends-with? (StringBuffer. "Conj") "West")))))
metabase/metabase
(ns metabase.api.metabot-test
(:require
[cheshire.core :as json]
[clojure.string :as str]
[clojure.test :refer :all]
[metabase.db.query :as mdb.query]
[metabase.metabot-test :as metabot-test]
[metabase.metabot.client :as metabot-client]
[metabase.metabot.util :as metabot-util]
[metabase.models :refer [Card]]
[metabase.test :as mt]
[toucan2.tools.with-temp :as t2.with-temp]))
(deftest metabot-model-happy-path-test
(testing "POST /api/metabot/model/:model-id happy path"
(mt/with-temp-env-var-value! [mb-is-metabot-enabled true]
(mt/dataset test-data
(t2.with-temp/with-temp
[Card orders-model {:name "Orders Model"
:dataset_query
{:database (mt/id)
:type :query
:query {:source-table (mt/id :orders)}}
:dataset true}]
(let [bot-message (format
"You should do ```SELECT COUNT(*) FROM %s``` to do that."
(metabot-util/normalize-name (:name orders-model)))
bot-sql (metabot-util/extract-sql bot-message)
q "How many orders do I have?"]
(with-redefs [metabot-client/*create-chat-completion-endpoint* (fn [{:keys [prompt_template]} _]
(case (keyword prompt_template)
:infer_sql {:choices [{:message {:content bot-message}}]}
{:choices [{:message {:content "{}"}}]}))
metabot-client/*create-embedding-endpoint* metabot-test/throw-on-embedding
metabot-util/*prompt-templates* (constantly metabot-test/test-prompt-templates)]
(let [response (mt/user-http-request :rasta :post 200
(format "/metabot/model/%s" (:id orders-model))
{:question q})
{:keys [query template-tags]} (get-in response [:card :dataset_query :native])]
(is (true? (str/ends-with? query bot-sql)))
(is (contains? template-tags (keyword (str "#" (:id orders-model)))))))))))))
(deftest metabot-database-happy-path-test
(testing "POST /api/metabot/database/:database-id happy path"
(mt/with-temp-env-var-value! [mb-is-metabot-enabled true]
(mt/dataset test-data
(t2.with-temp/with-temp
[Card orders-model {:name "Orders Model"
:dataset_query
{:database (mt/id)
:type :query
:query {:source-table (mt/id :orders)}}
:dataset true}]
(let [bot-model-selection (format "The best model is %s" (:id orders-model))
bot-sql-response (format "you should do ```SELECT COUNT(*) FROM %s``` to do that."
(metabot-util/normalize-name (:name orders-model)))
bot-sql (metabot-util/extract-sql bot-sql-response)
q "How many orders do I have?"]
(with-redefs [metabot-client/*create-chat-completion-endpoint* (fn [{:keys [prompt_template]} _]
(case (keyword prompt_template)
:infer_model {:choices [{:message {:content bot-model-selection}}]}
:infer_sql {:choices [{:message {:content bot-sql-response}}]}
{:choices [{:message {:content "{}"}}]}))
metabot-client/*create-embedding-endpoint* metabot-test/simple-embedding-stub
metabot-util/*prompt-templates* (constantly metabot-test/test-prompt-templates)]
(let [response (mt/user-http-request :rasta :post 200
(format "/metabot/database/%s" (mt/id))
{:question q})
{:keys [query template-tags]} (get-in response [:card :dataset_query :native])]
(is (true? (str/ends-with? query bot-sql)))
(is (contains? template-tags (keyword (str "#" (:id orders-model)))))))))))))
metabase/metabase
(ns metabase.driver.util-test
(:require
[clojure.java.io :as io]
[clojure.string :as str]
[clojure.test :refer :all]
[metabase.driver.h2 :as h2]
[metabase.driver.util :as driver.u]
[metabase.lib.test-metadata :as meta]
[metabase.lib.test-util :as lib.tu]
[metabase.public-settings.premium-features :as premium-features]
[metabase.query-processor.store :as qp.store]
[metabase.test :as mt]
[metabase.test.fixtures :as fixtures])
(:import
(java.nio.charset StandardCharsets)
(java.util Base64)
(javax.net.ssl SSLSocketFactory)))
(deftest ^:parallel generate-identity-store-test
(testing "proper key and cert files are read"
(let [key-string (-> "ssl/mongo/metabase.key" io/resource slurp)
key-passw "passw"
cert-string (-> "ssl/mongo/metabase.crt" io/resource slurp)
key-store (driver.u/generate-identity-store key-string key-passw cert-string)
[alias & alien-aliases] (-> key-store .aliases enumeration-seq)]
(is (string? alias))
(is (str/ends-with? alias "cn=localhost,ou=metabase,o=metabase inc.,l=san francisco,st=ca,c=us"))
(is (empty? alien-aliases))
(is (some? (.getCertificate key-store alias)))
(is (some? (.getKey key-store alias (char-array key-passw)))))))
clojure/clojurescript
(ns clojure.string-test
(:require [cljs.test :as test
:refer-macros [deftest is testing]]
[clojure.test.check :as tc]
[clojure.test.check.clojure-test :refer-macros [defspec]]
[clojure.test.check.generators :as gen]
[clojure.test.check.properties :as prop :include-macros true]
[clojure.string :as s]))
(testing "Testing string ends-with?"
(is (s/ends-with? "Clojure West" "West"))
(is (not (s/ends-with? "Conj" "West"))))
status-im/status-mobile
(ns legacy.status-im.utils.signing-phrase.core-test
(:require
[cljs.test :refer-macros [deftest is]]
[clojure.string :as string]
[legacy.status-im.utils.signing-phrase.core :refer [generate]]))
(deftest test-generate
(doseq [_ (range 30)]
(let [result (generate)]
(is (not (string/starts-with? result " ")))
(is (not (string/ends-with? result " ")))
(is (= (get (frequencies result) " ") 2)))))
arcadia-unity/Arcadia
(ns clojure.test-clojure.string
(:require [clojure.string :as s])
(:use clojure.test))
(deftest t-ends-with?
(is (s/ends-with? "Clojure West" "West") ;;; (StringBuffer. "Clojure West")
(is (not (s/ends-with? "Conj" "West"))))) ;;; (StringBuffer. "Conj")