#include "config.h"

#include "plugins/bkpr/sql.c"
#include "plugins/libplugin.c"

#include <common/clock_time.h>
#include <common/json_filter.h>
#include <common/json_stream.h>
#include <common/fee_states.h>
#include <common/setup.h>
#include <common/utils.h>
#include <stdio.h>
#include <wire/wire.h>

/* AUTOGENERATED MOCKS START */
/* Generated stub for find_blockheight */
u32 find_blockheight(const struct bkpr *bkpr UNNEEDED, const struct bitcoin_txid *txid UNNEEDED)
{ fprintf(stderr, "find_blockheight called!\n"); abort(); }
/* Generated stub for new_channel_event */
struct channel_event *new_channel_event(const tal_t *ctx UNNEEDED,
					const char *tag UNNEEDED,
					struct amount_msat credit UNNEEDED,
					struct amount_msat debit UNNEEDED,
					struct amount_msat fees UNNEEDED,
					const struct sha256 *payment_id TAKES UNNEEDED,
					u32 part_id UNNEEDED,
					u64 timestamp UNNEEDED)
{ fprintf(stderr, "new_channel_event called!\n"); abort(); }
/* AUTOGENERATED MOCKS END */

int main(int argc, char *argv[])
{
	common_setup(argv[0]);
	/* No quote: should return same pointer */
	const char *s1 = "simple";
	const char *r1 = sql_string(tmpctx, s1);
	assert(r1 == s1);

	/* One quote: should return new string with doubled quote */
	const char *s2 = "O'Reilly";
	const char *r2 = sql_string(tmpctx, s2);
	assert(strcmp(r2, "O''Reilly") == 0);
	assert(r2 != s2); // New allocation

	/* Multiple quotes */
	const char *s3 = "'a'b'c'";
	const char *r3 = sql_string(tmpctx, s3);
	assert(strcmp(r3, "''a''b''c''") == 0);

	/* All quotes */
	const char *s4 = "''''";
	const char *r4 = sql_string(tmpctx, s4);
	assert(strcmp(r4, "''''''''") == 0);

	/* Empty string: should return same pointer */
	const char *s5 = "";
	const char *r5 = sql_string(tmpctx, s5);
	assert(r5 == s5);
	common_shutdown();
}
